统计文件中单词数量

0 views
Skip to first unread message

bruc...@gmail.com

unread,
Sep 29, 2005, 10:15:51 PM9/29/05
to 星星爱CPP
[题目]
假设文件中的单词为由一个或多个空字符分隔的字符串,编写一个程序,计算指定文件中的单词数。

[答案]
#include <iostream>
#include <algorithm>
#include <iterator>
#include <fstream>
#include <string>
using namespace std;
int main( void )
{
ifstream in( "test.txt" );
cout << distance(
istream_iterator<string>(in),istream_iterator<string>() ) << endl;

return 0;
}

---

Reply all
Reply to author
Forward
0 new messages