0

In my readFile.h file, I define

void readFileInformation(string filename)

in readFile.cpp file, I define

void readFile::readFileInformation(string filename) {

ifstream inFile;
infile.open(filename.c_str(), ifstream::in);

...
}


in main.cpp file, I used

string filename="mgolfinput.txt"
readFile filereader;
filereader.readFileInformation(filename.c_str());


but for some reason, I couldn't open file. I did try to change path of .txt file as well.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Nick Evan
0

you should change filereader.readFileInformation(filename.c_str()); to: filereader.readFileInformation(filename); .

Your function expects a std::string, so no need to convert it to a char array first. Because you do that here: infile.open(filename.c_str(), ifstream::in); Next time use code-tags when posting code.

0

I have also tried that, but the program exit with "can't open file".

Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.