Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Hello World Tutorial Error

Tags:

c++

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

like image 416
user3280763 Avatar asked Feb 13 '23 21:02

user3280763


1 Answers

Missing #include <string> for string.

like image 67
wesley.mesquita Avatar answered Feb 16 '23 11:02

wesley.mesquita