-
Problem with getline()
I'm new to programming so please be patient with me :D
I'm trying to run a very simple code in Windows XP and in Code::Blocks with Borland Compiler (5.5, 5.82):
Code:
#include <iostream>
using namespace std;
string bla;
int main()
{
getline(cin, bla);
cout << "You entered: " << bla << endl;
}
as i press F9 to compile, the program crashes (it shows the usual "b.exe has encountered a problem and needs to close. We are sorry for the inconvenience." window)
and in cmd it returns 0xC0000005 error
If i use just "cin>>" everything works normaly...
What is the problem and what can i do to manage it?
-
You forgot to include the string header.
Edit: Warnings and errors mean things; but in this case was not the problem.
Tested OK with 6.1 bcc.
Edit: Tested with bcc 5.5.1 and it crashed.
Edit: Tested with bcc 5.8.2 and it worked.
Edit: Tested with bcc 5.9.2 and it worked.
Looks like you need to upgrade to a newer version of bcc
Tim S.
-
Why are you using Borland? Old, poor compiler. Use GCC, that is my suggestion.
-
I switched to GCC and it worked, no more crashes... Tnx Elysia... i'll use GCC from now on then...
@stahta01: I notice the errors and the warnings, but it didnt even come to that because it crashed before anything happened...