how i use string

how i can use string here ?

char fullname[20];
cout<<"\nEnter your <full name>:";
cin>>fullname;



when i leave space between my name it break the program
how i can use string please need help
To enter a full name, such as John Doe, you will need to use getline otherwise it will only take the word before the space.

So,
1
2
3
string fullname;
cout << "Enter full name: ";
getline(cin, fullname);
i have used that i am using that codes in for loop so program doesnt want my name i dont know why ?
what else i can use
I don't understand your issue. Please clarify
when i use this code ==> getline(cin, fullname);

program doesnt want my name just it show in enter your name but
there is no line to enter my name
do you understand ?
Are you sure?

Try:
1
2
3
4
string fullname;
cout << "Enter name: ";
getline(cin, fullname);
cout << fullname;

Enter your name and see if it reports.
i am definitely sure i Cant enter my name what i have to do ?
It does work. You must put the code in a program and compile it and then run it.

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

int main()
{
using std::string;
 using std::cin;
 using std::cout;
string fullname;
cout << "Enter name: ";
getline(cin, fullname);
cout << fullname;
 return 0;
}

Last edited on
thank you :)
Topic archived. No new replies allowed.