我的文本文件包含如果語句不工作,甚至說法是正確的
Wew213
Wew214
Wew215
和我的程序輸入是
Wew213
,但它告訴我輸出
"Not Matched"
其實什麼我正在做的是我想輸入輸入,如果輸入匹配文本文件中的數字,它應該運行if語句的輸出否則els Ë聲明
這裏是我的程序
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 always](http://stackoverflow.com/questions/5431941/while-feof-file-is-always-wrong)。 – 2013-12-08 21:12:28
@ H2CO3我讀了兩遍,但沒有明白他的意思,這是'while(!eof(file))'再次讀取文件比它需要 – AHF
Yap。 [15個字符] – 2013-12-08 21:45:05