我不断收到“打开文件失败”。我尝试将“dino.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")