我不断收到“打开的文件失败”。我试着将“dino.dat”文件放在与运行代码相同的文件夹中。我试过把它放入项目本身。下有项目 - 复制文件试图“构建阶段”选项卡(????)如何读取xcode 4中的.dat文件?
void ShowDino()
{
glColor3f(0,0,0); //set the drawing color
glLineWidth(3); //set the point size
//glBegin(GL_POLYGON);
//glVertex2d(randomPx,randomPy); //Set the position of the vertex
ifstream infile;
infile.open ("dino.dat");
if(!infile)
{
cout << "open file failed\n";
exit(0);
}
N_MAP_POINTS=0;
while(!infile.eof())
{
infile >> polylines; //read how many polylines
for(int i = 0; i<polylines; i++)
{
infile>>line;
glBegin(GL_LINE_STRIP);
for(int j = 0;j<line;j++) //read each lines
{
infile >> x >> y;
glVertex2d(x, y);
}
glEnd();
}
我以为我复制了“dino.dat”到文件夹中的代码驻留。在Visual Studio中,这就是它的工作原理。思想Xcode可能是相似的。那么,你告诉我,我应该读的完整路径,有点像:
infile.open ("/Users/me/Desktop/dino.dat")
我相信你的意思是“流入infile;'而不是'ifstream infile;' – 2012-03-11 02:06:12
”我将dino.dat复制到代码所在的文件夹中“这不会改变你的_compiled program_而不会改变你的_source code_你的文件。调试时编译的可执行文件未放置在项目文件夹中。 – 2012-03-13 13:18:20