File name with whitespace: Can not read!
Nov 26, 2009 at 3:47am UTC
Hi,
I am using the code:
1 2 3 4 5 6 7 8 9
string f = m.getfilename();
cout << "Arquivo: " << f << " " ;
iFile.open(f.c_str());
if (!iFile) { // file couldn't be opened
std::cerr << "Error: file could not be opened" << endl;
exit(1);
} else {
// cout << "Abrindo arquivo: " << m.getfilename() << endl;
}
where
ifstream iFile;
This works but when the file name has a space like in "file 2.dat", then this code fails to read the file.
What I can do to overcome this little bug?
Nov 26, 2009 at 5:46am UTC
I think that may be there is a '\0' in string f, so f.c_str() is not the really file name.
you can step into iFile.open() method to watch the file name.
Nov 26, 2009 at 8:45am UTC
What is the code inside getfilename ?
Nov 29, 2009 at 6:46am UTC
I guess getfilename() is not returning the filename u expect
Topic archived. No new replies allowed.