我有一个要在 C++ 程序中加载的简单数据文件。由于奇怪的原因,它不起作用:
- 我在 Windows 上尝试过,假设文件位于同一目录中:failed。
- 我通过移动 C:\ 目录中的文件在 Windows 上进行了尝试:工作。
- 我在 Linux 上尝试将文件放在同一目录中:failed。
片段:
void World::loadMap(string inFileName) {
ifstream file(inFileName.c_str(), ios::in);
if (file) {
}
else
{
cout<<"Error when loading the file \n";
exit(-1);
}
}
我这样调用 loadMap 方法:
World::Instance()->loadMap("Map.dat");
(世界是一个单例类)。
如何通过使用 try-catch 或其他任何方法找到确切的错误?