简体   繁体   English

为什么我不能用Code :: Blocks C ++读取文件?

[英]Why can't I read a file with Code::Blocks C++?

I've created a file in Code::Blocks called datos.csv , and I have this code: 我已经在Code :: Blocks中创建了一个名为datos.csv的文件,并且我有以下代码:

std::ifstream file("datos.csv");
if (file) {
    cout << "Managed to read file successfully.";
}else{
    cout << "Unable to read file.";
}

But it is unable to read the file. 但是它无法读取文件。

I tested the same code with TextMate, which can run C++ files, and it was indeed able to read the file, so I suppose there's something up with Code::Blocks. 我使用TextMate测试了相同的代码,该代码可以运行C ++文件,并且确实能够读取该文件,因此我想Code :: Blocks可以解决问题。 What am I missing? 我想念什么?

My file appears listed in "Others" in Code::Blocks' navigator. 我的文件出现在Code :: Blocks导航器的“其他”中。

you need to modify the Target Properties, go to Project -> Properties -> Build targets and change the "Executing Working Dir" for the debug/release folder of your proyect, I hope this help. 您需要修改“目标属性”,转到“项目”->“属性”->“构建目标”,然后更改您的proyect的debug / release文件夹的“ Executing Working Dir”,希望对您有所帮助。

Greetings. 问候。 Saludos. Saludos。

It can't find the file to open it. 它找不到打开文件。 Since you are not using absolute paths to open the file it must be relative to the current working directory. 由于您没有使用绝对路径打开文件,因此它必须相对于当前工作目录。 If you are launching from the debugger you can set the working directory used when the application is launched. 如果要从调试器启动,则可以设置启动应用程序时使用的工作目录。 Make sure that directory is the same as where the csv file is located. 确保该目录与csv文件所在的目录相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM