c – 无法让ifstream在XCode中工作

前端之家收集整理的这篇文章主要介绍了c – 无法让ifstream在XCode中工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
无论我尝试什么,我都无法使用以下代码来正常工作.

ifstream inFile;
inFile.open("sampleplanet");
cout << (inFile.good()); //prints a 1
int levelLW = 0;
int numLevels = 0;
inFile >> levelLW >> numLevels;
cout << (inFile.good()); //prints a 0

在第一个cout<< (inFile.good());,它打印一个1,第二个打印0.这告诉我文件正确打开,但是一旦从中读入,inFile就会失败.该文件具有足够多的行/字符,因此我无法通过该点尝试读取文件末尾. 文件内容

8
2
#level 2
XXXXXXXX
X......X
X..X..XX
X.X....X
X..XX..X
XXXX...X
X...T..X
XXX..XXX
#level 1
XXXXXXXX
X......X
X..X.XXX
X.X..X.X
X..XX..X
X......X
X^....SX
XXX.^XXX

解决方法

这是一个已知的错误.来自Xcode 3.2.1的 Release Notes

The default gcc 4.2 compiler is not
compatible with the Standard C++
Library Debug Mode. C++ programs
compiled with Xcode 3.2 may not work
in the Debug configuration. To fix
this,set the Compiler Version to 4.0,
or edit the Debug configuration’s
Preprocessor Macros and remove the
entries:
_GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1

猜你在找的Xcode相关文章