2016-06-14 99 views
-2
#include <iostream> 
#include <fstream> 

using namespace std; 

int main() 
{ 
    int A; 
    ifstream file("file.txt"); // there is a single "8" in the file 
    file >> A; 
    cout << A; // I get 0 always 


    return 0; 
} 

虽然我并不陌生CodeBlocks,但我是Mac上的CodeBlocks的新手。我已经更改了“执行工作目录”,但它仍然无效,请帮助。Mac上的CodeBlocks没有读取文件

+0

我以前看过我们应该在build目标属性中设置执行目录看看。 – 13krn

回答

0

不要改变执行工作目录。当你从文件中读取,试着写出完整的目录,其中是文件,例如:

// this is your file.txt location 
ifstream file("C:\\Desktop\\file.txt"); // this is for Windows 

,然后运行程序。 如果还是不行,试试看这个教程:https://www.youtube.com/watch?v=De6trY8FRYY