使用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分割的单词

浙公网安备 33010602011771号