![]() |
|
#1
|
|||
|
|||
Cin stringI want to input sth and store it by string. However, when I input the words that contains space, the variable only store the characters after the space
eg...Good Boy <--only store the Boy in the variable string word; cin >> word; How to solve this problem? Also, I want to hold the screen in sub menu? When user click enter, the sub menu go back to main menu |
|||
|
#2
|
||||
|
||||
|
Quote:
Use cin.getline(word) for char *, or getline(cin, word) for string CPP / C++ / C Code:
Don't forget using namespace std; Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
Luci's code doesn't workQuote:
It still only reads Boy. |
|
#4
|
||||
|
||||
|
Quote:
Really ![]() What compiler did you use? It works fine under Visual C++ 6.0. Maybe it's not correct for other compilers? There is a certain problem with *older* VC compilers (including 6), but this does not affect the reading of your line. There is also a problem with using getline after getline. Maybe you did this? Because there is a newline pushed in by the environment - nobody knows why . You can solve this by using a "dummy" variable to "catch" the newline:CPP / C++ / C Code:
Or, you could use ignore to get rid of this annoying "feature": CPP / C++ / C Code:
Hope this solves your problem. If not, please let me know! Kind regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#5
|
|||
|
|||
I'm using Dev C++ 4.9.9.0Quote:
I'm using Dev C++ 4.9.9.0. I was trying to find one easy way to read in the User's Input: "First Middle Last" or "First Last" as 1 complete String instead of splitting them into 3 Strings, then joining them back. |
|
#6
|
||||
|
||||
|
I'm sorry, I don't have this compiler, nor can I install it on this machine.... Hope someone who works with it will help you out. My solutions work correct under Visual C. I don't know what the problem is with your compiler.
Regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read a .html file, check that file for links | salemite | C Programming Language | 10 | 17-Jan-2008 08:56 |
| Re: Conversion: Binary, Decimal, Hexadecimal | WaltP | C Programming Language | 1 | 10-May-2006 07:49 |
| Including Maps and strings?? | maddie | C++ Forum | 17 | 05-Jul-2004 07:25 |
| storing a token pointer as a string | CoreLEx | C Programming Language | 1 | 07-Oct-2003 12:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The