I'm attempting to use a string retrieved from a vector to pass a filename to ifstream for opening.
vector<string> files;
//Populate vector
std::ifstream if开发者_如何学运维ile(files[0] ,std::ios::binary);
When compiled This returns:
error: no matching function for call to 'std::basic_ifstream >::basic_ifstream(std::basic_string, std::allocator >&, const std::_Ios_Openmode&)*
If I attempt to convert files[0] to const char * first
vector<string> files;
std::string l = files[0];
const char *p;
p = l.c_str();
std::ifstream ifile(p ,std::ios::binary);
The compiler returns:
error: 'l' was not declared in this scope
What am I doing wrong here? It's something basic and glaring i'm sure.
Try this:
std::ifstream ifile(files[0].c_str(), std::ios::binary);
精彩评论