-2
#include <iostream>
#include <fstream>
//#include <cstring>
//#include <string>
using namespace std;
int main()
{
string word;
ifstream infile;
infile.open ("inputfile.txt");
if (infile.fail())
{
cout<<"UNABLE TO ACCESS INPUT FILE";
}
while(!infile.eof())
{
while (infile>> word)
{
cout<<word<<endl<<endl;
}
}
infile.close();
system("pause");
return 0;
}
上面的代码COUTS在输入文本文件中的所有词语的我如何只选择一个字?我问这个,因为我希望最终能够从用户CIN一个字,并找到在输入文件或者删除或者用另一个词替换这个词。如何从包含多个句子的输入文件中查找单个单词。 C++
你可以使用if语句来检查什么字呢打印出来 – Gab
首先请阅读前[为什么的iostream算错了一个循环条件中:: EOF ?](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong)。然后想想你最内层循环做什么(不需要外部,并且是错了,因为你现在已经阅读)。 –