I don’t understand why this isn’t working. For some reason I’m getting the error:
error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
I’m doing this in Visual Studio2010 C++ Express if that helps. Not sure why its handing me this error I’ve done other programs using cin…
My Code:
#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;
}
}
include
<string>On top of that I suggest you use getline instead as >> will stop at the first word in your input.
Example:
The result is “C:\Users\Andrew”, quite unexpected considering that the data is not consumed until the newline and, the next std::string read will automatically be consumed and filled with “Finnell\Documnts\MyFile.txt”
This will consume all text until the newline.