Я начинающий программист на 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 (product> scheme> edit scheme> options (внутри run), а затем сменить каталог в каталог, где находится ваш код. –