Hey I'm new and i have a question

Write your question here.

To my knowledge strings are just objects that hold more than one group of characters. However I'm confused about "getline and

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// extract to string
#include <iostream>
#include <string>
using namespace std;
main ()
{
  string name;

  cout << "Please, enter your full name: ";
  getline (cin,name); /*why not just use cin >> name */
  cout << "Hello, " << name << "!\n";

  return 0;
}  

any help would be greatly appreciated
Last edited on
Thanks for the help after experimenting i found the following results

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// extract to string
#include <iostream>
#include <string>
using namespace std;
main ()
{
  string name;

  cout << "Please, enter your full name: ";
  getline (cin,name);
  cout << "Hello, " << name << "!\n";

  return 0;
}  


When I enter my full name here "Brian Rivera" it shows my full name.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
using namespace std;
main ()
{
  string name;

  cout << "Please, enter your full name: ";
  cin >> name; //would this be another way to write the code?
  cout << "Hello, " << name << "!\n";

  return 0;
}  


When i enter my full name here it shows only "Brian".
Topic archived. No new replies allowed.