如何实现读取文件并统计单词个数和最长单词字母个数呢?
学校作业,苦逼大一新生,求助只会写#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
ifstream infile;
ofstream outfile;
infile.open(argv[1]);
if(infile.fail()){
cerr<<"Error: Input file cannot be opened"<<endl;
return -1;
}
if(outfile.fail()){
cerr<<"Error: Output file cannot be opened"<<endl;
return -1;
}
int wordCount = 0;
while(!infile.eof()){
char c= infile.get();
if(c==' '){
wordCount++;
}}
return 0;
}
这一部分