Issues with cin

May 22, 2013 at 10:52pm
I need to send an ifstream variable to a function, but the file directory needs to be user-defined. I have:
1
2
ifstream inData;
cin >> inData;


The >> operator becomes highlighted with an error message: no operator ">>" matches these operands.

I receive the same message for string types but not for integers or doubles.
May 22, 2013 at 11:24pm
closed account (Dy7SLyTq)
thats not how that works. you use
ifstream::open(char* FileName) // can also specify flags after file name
c++11: open(std::string)
May 23, 2013 at 4:25am
What if I don't have the file name though? I need to write the program so it collects the directory location from the user.
May 23, 2013 at 4:40am
1
2
3
4
std::string filename = "";
std::cout << "Please enter a filename.\n> " << std::flush;
std::cin >> filename;
ifstream in( filename.c_str() );
May 23, 2013 at 5:42am
closed account (Dy7SLyTq)
unless your doing c++ 11 in which case you dont need the .c_str()
Topic archived. No new replies allowed.