【发布时间】:2013-12-08 21:04:48
【问题描述】:
我的文本文件包含
Wew213
Wew214
Wew215
我在程序中的输入是
Wew213
但它显示输出
"Not Matched"
实际上我正在做的是我想输入输入,如果输入与文本文件中的数字匹配,它应该通过 if 语句运行输出,否则为 else 语句
这是我的程序
char file_data[10];
std::ifstream file_read ("D:\\myfile.txt");
cout<<"Enter the number to search"<<endl;
char val[10];
cin>>val;
while(!file_read.eof())
{
file_read>>file_data;
cout<<file_data<<endl;
}
if (val == file_data)
{
cout<<"Matched"<<endl;
}
else
{
cout<<"Not Matched"<<endl;
}
}
【问题讨论】:
-
while(!eof(file))是always wrong。 -
@H2CO3 我读了两遍,但没明白他的意思,这是不是
while(!eof(file))比它需要的多读了一次文件
标签: c++