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.

Recommended Answers

All 3 Replies

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.

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

Thanks

Show the complete code and attach the file. Also tell me where the file is located on your harddrive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.