Program2

Hello,

I have just started doing the exercises of chapter 3 objects,types and values and I`m stumbling.

I have a code which looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;


int main()

{

      cout<<"Enter the name of the person you want to write to:\n";
      string first_name;              // first name is a variable of type string
      cin>>first_name;                // read characters into first_name
      cout<<"Dear,"<<first_name<<"\n";
      cout<<"How are you? I am fine. I miss you\n";   


Now here is the exercise:

Prompt the user for the name of another friend and store it in friend_name. Add a line to your letter: "Have you seen friend_name lately?"

Here is something I put together and obviously failed (at least according to the compiler)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;


int main()

{

      cout<<"Enter the name of the person you want to write to:\n";
      string first_name;              // first name is a variable of type string
      cin>>first_name;                // read characters into first_name
      cout<<"Dear,"<<first_name<<"\n";
      cout<<"How are you? I am fine. I miss you\n";
      cout>>"Give me a name of any friend:\n";   // prompting the user for the name of another friend
      string friend_name;                 // friend_name is a variable of type string
      cin>>friend_name;                   // read characters into friend_name
      cout<<"Have you seen"<<friend_name<<" lately?\n";       

}   



Any suggestions are welcome, thanks


Last edited on
failed (at least according to the compiler)

What did the compiler say?
1
2
3
4
prog.cpp: In function ‘int main()’:
prog.cpp:18:11: error: no match foroperator>>’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘const char [31]’)
       cout>>"Give me a name of any friend:\n";   // prompting the user for the name of another friend
           ^


This says the error is in line 18 and has to do with the operator >> used. Since this is a cout statement, you need the << operator, not >>.
That one used to get me all of the time too.
Topic archived. No new replies allowed.