XCode中为何ifstream配置后仍无法正常工作?

2026-04-16 17:112阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计323个文字,预计阅读时间需要2分钟。

XCode中为何ifstream配置后仍无法正常工作?

无论我尝试什么,我都无法使用以下代码进行正常工作。

cppifstream inFile;inFile.open(sampleplanet);cout << (inFile.good()) <> levelLW >> numLevels;cout << (inFile.good()) < 无论我尝试什么,我都无法使用以下代码来正常工作.

XCode中为何ifstream配置后仍无法正常工作?

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

本文共计323个文字,预计阅读时间需要2分钟。

XCode中为何ifstream配置后仍无法正常工作?

无论我尝试什么,我都无法使用以下代码进行正常工作。

cppifstream inFile;inFile.open(sampleplanet);cout << (inFile.good()) <> levelLW >> numLevels;cout << (inFile.good()) < 无论我尝试什么,我都无法使用以下代码来正常工作.

XCode中为何ifstream配置后仍无法正常工作?

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