0

hi i got an problem about reading my files i want to decide which file to open in the program not before anyone now a solution? :)

string fil;
	cout<<"which file?  : ";
	cin>>fil;
	ifstream myfile(fil);

cant see why this dont work...

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Dendei
0

Well you might want to use getline(), but the reason it doesn't work is that the ifstream constructor requires a C-Style string i.e. null terminated character array, not an object of type string. Thus you will need to use.

ifstream myfile(fil.c_str());

Chris

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.