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...

Recommended Answers

All 2 Replies

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

works nice thank you :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.