问题
I am trying to get my program to read a file and use the file as input information. I put the file in the same directory as my program, but still nothing.
Here is my code:
int main()
{
ifstream inFile;
inFile.open("inData.txt");
if (inFile.fail())
{
cout << "file did not open please check it\n";
system("pause");
system("exit");
}
studentType sList[20];
getData(inFile, sList, 20);
calculateGrade(sList, 20);
printResult(sList, 20);
inFile.close();
system("pause");
return 0;
}
回答1:
Compile and run this program from the same location your program is. Wherever it creates the file output.txt is your working directory:
#include <fstream>
int main(int argc, char **argv)
{
std::ofstream myfile;
myfile.open("output.txt");
myfile << "output\n";
myfile.close();
return 0;
}
When you run your program, put your inData.txt file in that directory.
来源:https://stackoverflow.com/questions/51567426/what-is-the-working-directory-of-my-c-program