+ 1

program not print the word after space please guide me

program not print the word after space please guide me #include<iostream> using namespace std; int main(void){ char a[10]; cout<<"enter Name"; cin>>a; int i=0; cout<<a; return 0; }

2nd Oct 2018, 4:04 AM
Umar Farooq Anwar
Umar Farooq Anwar - avatar
3 Answers
+ 12
If you mean after a space that the user enters as input you will want to use std::getline() Since getline works with strings, you may also need to use a string instead of a char array. See: http://www.cplusplus.com/reference/string/string/getline/ Like so: #include<iostream> #include <string> using namespace std; int main(void){ //char a[10]; string a; cout<<"enter Name"; getline(cin,a); // cin>>a; int i=0; cout<<a; return 0; }
2nd Oct 2018, 4:34 AM
jay
jay - avatar
+ 3
Umar Farooq Anwar Do no foget to press the ✅ next to the answer that soved the question.
2nd Oct 2018, 5:32 AM
Manual
Manual - avatar
+ 1
thanku Jay and Ina
2nd Oct 2018, 4:36 AM
Umar Farooq Anwar
Umar Farooq Anwar - avatar