0
我是一名初學C++程序員,之前習慣於使用Visual Studio,但現在我正在使用mac,現在我使用xcode。在xcode中,我無法從文件中讀取數據(所以我也無法獲得輸出)。我應該在xcode中更改哪個設置以從文件讀取數據(該文件與項目位於同一文件夾中)正確嗎?無法從xcode中的文件讀取數據
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//in thefile.txt i only have a string "hello"
int main() {
string text; //since i only have a string in the file. So this is a variable representation for it
ifstream myfile;
myfile.open("thefile.txt");
myfile >> text; //extract the word from the file
cout << "The following is the data in the file: " << text <<endl; //trying to print The following is the data in the file: hello
return 0;
}
//Output is "The following is the data in the file: "
謝謝。它有幫助。我還通過xcode(產品>方案>編輯方案>選項(內部運行))找到了一種方法,然後將目錄切換到您的代碼所在的目錄。 –