What is up with space:
char pName[255];
cin >> pName;
"Input: Word then space";
string strName = pName;
cout << strName <<endl;
"Output: Word"
So I geuss, what is the correct way to accept user input...
Printable View
What is up with space:
char pName[255];
cin >> pName;
"Input: Word then space";
string strName = pName;
cout << strName <<endl;
"Output: Word"
So I geuss, what is the correct way to accept user input...
Cin reads until the first whitespace.
Try this:
Code:int main()
{
char pName[256];
cin.getline( pName, 256 );
cout << pName << endl;
}
Thats not working....
What you posted just tries to get the line which is not being inputted...
If I use cin then what you posted the first like 6 letters are always cut out...
How about this:
Code:#include <iostream>
#include <string>
using namespace std;
int main()
{
string buffer;
getline(cin, buffer);
}
It is always a good reason to flush the buffer before using a cin.getline()...
So try doing this and see if it helps...
Code:cin.flush()