I'm learning C++ by following examples in a book and after typing this out and double checking I keep getting error messages. I cant figure out what is wrong. I'm using Visual C++ 2010 if it matters.
#include <iostream>
using namespace std;
int main()
{
// Prompt the user for data
cout << "Please enter two words:" << endl;
//Read in the values
string b, c;
cin >> b >> c;
// Give feedback
cout << "I understood: "
<< b << ", and "
<< c << endl;
// NOw, lets's read a whole line of text as a single entity
cout << "Now, type in a whole line of text, "
<< "with as many blanks as you want:"
<< endl;
//getline() is a function; we'll talk more about them in Part3
string wholeLine;
getline( cin, wholeLine );
//In the cout statement below, remember that \"
// is an escape sequence!
cout << "I understood: \"" << wholeLine << "\"" << endl;
// And we're done!
return 0;
}
There are four errors. The error codes are:
Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion) i:\helloworld.cpp 11
Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) i:\helloworld.cpp 15
Error 3 error C3861: 'getline': identifier not found i:\helloworld.cpp 25
Error 4 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) i:\helloworld.cpp 29
Missing #include <string>
for string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With