|
-
June 7th, 2012, 05:42 PM
#1
opening files were name contains '
I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,
N,N'-dimethylethylenediamine.mol
I have been using this app for a while and I think I would have noticed this, but I haven't. Is there some reason why there would be a problem with the file name?
This is the function that opens the file,
Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );
// check if the file was opened
if(!read_mol_input.is_open()) {
cout << "mol file " << filePath << " could not be opened" << endl;
exit(-3);
}
// add each keep line to mol_file
while(getline(read_mol_input, new_mol_line)) {
// remove windows '\r' character if present
new_mol_line.erase (remove(new_mol_line.begin(),new_mol_line.end(),'\r') , new_mol_line.end());
// store keep values in vector
mol_file.push_back(new_mol_line);
}
return mol_file;
}
The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.
Should I expect there to be a problem with this as it is written, or is something else going on? I can post the code and test files if that would help.
LMHmedchem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|