|
-
Jul 22nd, 2005, 05:19 PM
#1
Thread Starter
PowerPoster
cin >> char with a space...
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...
Last edited by Halsafar; Jul 22nd, 2005 at 06:31 PM.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Jul 22nd, 2005, 05:42 PM
#2
Lively Member
Re: cin << char with a space...
Cin reads until the first whitespace.
Try this:
Code:
int main()
{
char pName[256];
cin.getline( pName, 256 );
cout << pName << endl;
}
-
Jul 22nd, 2005, 06:05 PM
#3
Thread Starter
PowerPoster
Re: cin << char with a space...
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...
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Jul 22nd, 2005, 06:42 PM
#4
Re: cin >> char with a space...
How about this:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string buffer;
getline(cin, buffer);
}
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Jul 24th, 2005, 12:00 PM
#5
Addicted Member
Re: cin >> char with a space...
It is always a good reason to flush the buffer before using a cin.getline()...
So try doing this and see if it helps...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|