levelLW >> numLevels; c-6ren">
gpt4 book ai didi

c++ - 无法让 ifstream 在 XCode 中工作

转载 作者:太空狗 更新时间:2023-10-29 20:19:06 25 4
gpt4 key购买 nike

无论我怎样尝试,我都无法让下面的代码正常工作。

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,在第二个 cout 中打印一个 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

关于c++ - 无法让 ifstream 在 XCode 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2107122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com