By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Input file path

P: 51
This is probably a noob question, but how do i have the user input a file path which is then opened by the program.

cout << "File:";
cin >> file_path;
ifstream file (file_path);

The above code returns some long complicated errors, and i don't know what else to try. Thanks in advance!

Peace.
Aug 12 '07 #1
Share this Question
Share on Google+
3 Replies


ilikepython
Expert 100+
P: 844
This is probably a noob question, but how do i have the user input a file path which is then opened by the program.

cout << "File:";
cin >> file_path;
ifstream file (file_path);

The above code returns some long complicated errors, and i don't know what else to try. Thanks in advance!

Peace.
How is file_path declared?
Aug 12 '07 #2

P: 51
sorry i forgot file_path is a std::string.
Aug 12 '07 #3

Ganon11
Expert 2.5K+
P: 3,652
Instead of

Expand|Select|Wrap|Line Numbers
  1. ifstream file(file_path);
try

Expand|Select|Wrap|Line Numbers
  1. ifstream file(file_path.c_str());
and see if that fixes the problems.
Aug 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.