使用c++实现按照单词读取文件

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    string str_file;
    ifstream infile("TEST");
    int wc = 0;
    while ( infile >> str_file )
    {
        wc ++;
        cout << str_file << endl;
    }
    cout << endl << "Total " << wc << " Words" << endl;
}

 

好处:可以兼容使用空格或者TAB分割的单词

posted @ 2014-05-10 08:14  刀刀  阅读(568)  评论(0)    收藏  举报