int test = 0;
ifstream inFile;
inFile.open("hat.txt");
inFile >> test;
cout << test;
我在调试文件夹中运行.exe文件,该文件的文件是hat.txt。它只有一个数字。我的问题是为什么我输出时会变得垃圾?垃圾简单读取
编辑 - 添加失败线,它确实失败。为什么失败?
int test;
ifstream inFile;
inFile.open("hat.txt");
if (inFile.fail())
{
cout << "It Failed" << endl;
}
inFile >> test;
cout << test;
是在正确的位置hat.txt? – 2011-04-20 22:27:00