TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JASON LAVOIE
from: DARIN MCBRIDE
date: 1997-09-22 19:43:00
subject: Re: string input

PW>  JL> for some reason I can't seem to input a string with spaces in it.
PW>  JL> am I missing something?   like:
PW>  JL> char testvar[100];   cin >> testvar;
PW>  JL> how come I only get the first word?
PW> 
PW> It stops reading when it hits whitespace, IIRC.
 JL> thanks, but is there any way to input a string with spaces in it?
 JL> (all into the same variable)
How do you know when the variable is supposed to stop getting characters?
If you have a sentinel character (a terminating character - such as the space 
above), you can use getline (you can optionally specify the sentinel).  I 
believe it is cin.getline(testvar, sizeof(testvar), sentinel) - if you don't 
specify the sentinel, a '\n' is used (i.e., the enter key).
Good luck!
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.