wordcount.cpp
来自「一个很好的计算文字数目的例子,现在一个缺点就是计算中文的时候可能不是很准确」· C++ 代码 · 共 56 行
CPP
56 行
///////////// wordcount.cpp ///////////////
#include <iostream>
#include <fstream.h>
//#include "file.cpp"
#include "wordcount.h"
//using namespace std;
char c_temp;
//写文件
void write_file( char ch )
{
fstream file;
file.open("data.txt",ios::app);
file<<ch;
file.close();
}
bool wordcount::readin()
{
char c;
while ( ! buf->isFull() )
if ( std::cin.get(c) )
{
buf->produce(c);
write_file(c);
if ( c == '#' && c_temp == '/')
return false;
c_temp=c;
}
else
return false;
return true;
}
void wordcount::count()
{
int c;
while ( ! buf->isEmpty() )
switch( c=buf->consume() )
{
case ' ':
case '\t':
case '\n':
if ( word ) wcnt++;
word=false;
break;
default:
word=true;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?