0

Hi,

I assigned the name of the file to string vector.

I mean when I print the vector, it seems like

cout<< files[0];

It prints file.txt

and I want to open the file by using vector.

I tried ifstream file ("files[0]"); and ifstream file (files[0]);

but they did not work. Please help me out !

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by airerdem
0

Are you sure the file exists and is in the correct folder? What do you mean by saying they do not work?
Are you getting compilation errors, or is it something else? It would really help if you posted your code.

1

Presumably you're using a vector of std::string. The fstream constructors don't have an overload for std::string, so you need to call c_str():

ifstream file(files[0].c_str());
This question has already been answered. 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.