Cin has no operand >>

I do not understand why this is not working. For some reason, I get an error:

error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)

I do this in Visual Studio2010 C ++ Express if that helps. Not sure why he passed me this error, I made other programs using cin...

My code is:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main(int argc, char* argv){
    string file;

    if (argc > 1)
    {
        file = argv[1];
    }
    else
    {
        cout << "Please Enter Your Filename: ";
        cin >> file;
    }
}
+3
source share
2 answers

turn on <string>

In addition, I suggest you use getline instead, since → will stop at the first word in your input.

Example:

std::cin >> file; // User inputs C:\Users\Andrew Finnell\Documents\MyFile.txt

Result: "C: \ Users \ Andrew", completely unexpectedly, given that the data is not consumed until a new line appears, and the next std :: string read will be automatically consumed and filled in "Finnell \ Documnts \ MyFile.txt" "

std::getline(std::cin, file); 

.

+6

<string>, . , operator>> . , , .

+1

All Articles