I am using Turbo C++ 3.0 Compiler
While using the following code ..
char *Name;
cin >> Name;
cout << Name;
When I gave input with space … its only saving characters typed before space ..
like if I gave input “QWERT YUIOP” … Name will contain “QWERT”;
Any explaination why ??
You need to allocate space for the char array into which you want to read the Name.
char *Name;will not work as it only declares a char pointer not a char array. Something likechar Name[30];Also the
cin <<only allows us to enter one word into a string (char name[30]).However, there is a cin function that reads text containing blanks.
get will read all characters including spaces until Max characters have
been read or the end of line character (‘\n’) is reached and will put them
into the name variable.