Issues with cin
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.
thats not how that works. you use
ifstream::open(char* FileName) // can also specify flags after file name
c++11: open(std::string)
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.
1 2 3 4
|
std::string filename = "";
std::cout << "Please enter a filename.\n> " << std::flush;
std::cin >> filename;
ifstream in( filename.c_str() );
|
unless your doing c++ 11 in which case you dont need the .c_str()
Topic archived. No new replies allowed.