无法让ifstream在XCode中工作 [英] cant get ifstream to work in XCode

查看:131
本文介绍了无法让ifstream在XCode中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我做什么,我都无法使以下代码正常工作.

No matter what I try, I cant get the following code to work correctly.

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

在第一个球上<< (inFile.good());,它打印一个1,第二个打印0.这告诉我文件正在正确打开,但是inFile一旦从文件中读取就失败了.该文件具有更多的行/字符,因此到那时为止,我都无法尝试读取文件末尾的内容.

at the first cout << (inFile.good());, it prints a 1 and at the second a 0. Which tells me that the file is opening correctly, but inFile is failing as soon as read in from it. The file has more then enough lines/characters, so there is no way I have tried to read past the end of the file by that point.

文件内容:

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

推荐答案

事实证明,这是X代码的问题.我使用相同的代码在net bean中创建了一个项目,没有任何问题.很奇怪.

It turned out to be an issue with X-Code. I created a project in net beans using the same exact code and had no problems. Weird.

更新: 在我的X代码项目中,我将活动的SDK从Mac OS 10.6更改为Mac OS 10.5,现在一切正常.

Update: In my X-Code project, I changed my active SDK from Mac OS 10.6 to Mac OS 10.5 and everything works fine now.

这篇关于无法让ifstream在XCode中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆