C ++ Error Hello World Tutorial

I learn C ++, following the examples in the book, and after entering this and double checking, I keep getting error messages. I can’t understand what’s wrong. I am using Visual C ++ 2010 if that 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 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. Error Codes:

Error 1 error C2678: binary '→': operator not found that accepts a left operand of type 'std :: istream' (or not an acceptable conversion) i: \ helloworld.cpp 11

Error 2 C2679: binary '<<: operator not found that accepts the right operand of type' std :: string '(or not an acceptable conversion) i: \ helloworld.cpp 15

Error 3 error C3861: 'getline': identifier not found i: \ helloworld.cpp 25

4 C2679: '< <: , 'std::string' ( ) i:\helloworld.cpp 29

+4
2

#include <string> string.

+7

, , .

, getline() cin . , . , , cin.ignore() cin getline. !

+1

Source: https://habr.com/ru/post/1525665/


All Articles