文档读取每一个字符——尤其是空格

来源:互联网 发布:php pack函数 编辑:程序博客网 时间:2024/06/05 11:31

fin>>noskipws; //可以强制读每一个字符,连空格也不漏掉!

这一行代码解决了我烦恼了很久的问题!

    ifstream fin;                                                //打开每个文件//为了便于观察中间结果,将拆出来的没有查过重的单词写入一个叫ori.txt的文档                                   fin.open(filename);    finn.open("G://ori.txt",ios::out | ios::app);    if (!fin)        cout<<"error!"<<endl;    if (!finn)        cout<<"error!"<<endl;    //添加全局函数进行文档内容处理——倒排索引的基础!!!!!!    //把打开的文件的每个词拆出来存入一个文件    int index;    char c;    fin>>noskipws;                      //注意!!!!!!!!!强制读每一个字符!!!!包括空格    while (!fin.eof())                                  {        index=1;        fin>>c;        if ((c>='a'&&c<='z')||(c>='A'&&c<='Z'))        {            index=0;            finn<<c;        }        else             if (index==1)            {                finn<<" ";                index=0;            }    }    finn.close();    fin.close();    return true;
0 0
原创粉丝点击