| | |
Mystery with getline, very simple program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 42
Reputation:
Solved Threads: 0
I ran the following simple program 10 minutes ago and it worked as expected, i.e. it took input "monster" which contained spaces. But few minutes later I copied the program exactly the same to save as a new program, and it doesn't take the spaces in "monster" input any more--if the input for monster is "John Doe", then it's displayed as only "J". What's happening? I even restarted my computer and still doesn't fix it! Exactly this program:
Update: Well, I retyped the exact same program again, saved as yet another new file name, and this time it worked! The previous program (exactly the same statements) still doesn't work! What's going on??? So strange!
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { string monster; cout << "Enter monster: "; getline(cin, monster); cout << "You entered: " << monster << endl; cin.get(); return 0; }
Update: Well, I retyped the exact same program again, saved as yet another new file name, and this time it worked! The previous program (exactly the same statements) still doesn't work! What's going on??? So strange!
Last edited by sgw; Feb 8th, 2009 at 11:43 pm.
Delete that file and re-copy and paste.
That is VeRy StRaNgE huh!
May be taking it to "computer mental hospital" can help recognize what is wrong ...........hehehe
That is VeRy StRaNgE huh!

May be taking it to "computer mental hospital" can help recognize what is wrong ...........hehehe
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
@XTRobot
I know your problem's solved, but I thought I felt like saying that I'd advise against using DevC++. I used to use it, but it's been dead since 2005, so I'd use something like GCC or CodeBlocks now to keep the compiler up to date.
I know your problem's solved, but I thought I felt like saying that I'd advise against using DevC++. I used to use it, but it's been dead since 2005, so I'd use something like GCC or CodeBlocks now to keep the compiler up to date.
Last edited by shadwickman; Jun 29th, 2009 at 6:20 am.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
What you can also try is just recompiling the source of the file which is behaving incorrectly.
(I compiled this source successfully using MinGW).
What compiler are you using ?
Could you just attach the whole file (the source of the file which doesn't work correctly) to this thread?
(and if possible: the executable file as well)
So I can check it by running it on my computer.
(I compiled this source successfully using MinGW).
What compiler are you using ?
Could you just attach the whole file (the source of the file which doesn't work correctly) to this thread?
(and if possible: the executable file as well)
So I can check it by running it on my computer.
Last edited by tux4life; Jul 2nd, 2009 at 10:58 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
He said he was running it on Dev C++ in his post a few up. Hence my suggestion to use MinGW or a non-dead compiler to keep up to date.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
I think you're confusing XTRobot with the OP (sgw)
Actually Dev-C++ uses MinGW as it's compiler but it's an older version, so I'd also recommend him to upgrade his compiler.
Normally you can configure Dev-C++ to work with the new MinGW compiler, so he can continue to use Dev-C++, but with the new MinGW compiler, this shouldn't be a problem.
•
•
•
•
Hence my suggestion to use MinGW or a non-dead compiler to keep up to date.
Normally you can configure Dev-C++ to work with the new MinGW compiler, so he can continue to use Dev-C++, but with the new MinGW compiler, this shouldn't be a problem.
Last edited by tux4life; Jul 2nd, 2009 at 3:18 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Other Threads in the C++ Forum
- Previous Thread: Path to the .exe Being Run
- Next Thread: Want to save and load info to and from a txt file thats in a listbox
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game generator getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






