Visual Microsoft is telling me this coding is wrong?

I was working on some coding and the book told me to do this:

#include <iostream>

using namespace std;

int main()
{
string name;
cout << "Please type your name: ";
cout >> name;
cout << "Your name is " << name << endl;
system("PAUSE");
return 0;
}


It is telling me that 'cout >> name;' And '<< name' are "Error: no operator ">>" matches these operations." Help Please?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <iostream>

using namespace std;

int main()
{
string name;
cout << "Please type your name: ";

// cout >> name;  // your code...

// correct code is to use cin...
cin >> name; // new code.. 

cout << "Your name is " << name << endl;
system("PAUSE");
return 0;
}
I suspect it probably told you to do this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
    string name;
    cout << "Please type your name: ";
    cin >> name;    //this line is different from your code
    cout << "Your name is " << name << endl;
    system("PAUSE");
    return 0;
}
You also need to include string.
Topic archived. No new replies allowed.