Page 1 of 1

getline(cin, mystring); not working.......

Posted: Thu Jan 06, 2005 3:59 pm
by CodeMaker
Hi, can you tell me why it is not working? :(

Code: Select all

#include<iostream>
#include<string>

using namespace std;

int main()
{
      string mystring;

      getline(cin,mystring);

      cout<<mystring;
 
      return 0;
}
after I write something and then press "enter", it doesn't work then if I press "enter" again then it takes the input. how can I solve this problem?

Posted: Thu Jan 06, 2005 5:49 pm
by tat tvam asi
Hi
Isn't it an IDE related question? It works on my box except that it
doesn't print any newline char. I tested it under GNU/Linux with g++.
( and my "IDE" is bash+gcc+mc :) )
Csaba Noszaly.

Posted: Thu Jan 06, 2005 11:29 pm
by Cahoun
Try change

Code: Select all

cout<<mystring; 
to

Code: Select all

cout<<mystring<<endl; 

Posted: Sun Jan 16, 2005 9:55 am
by A1
after I write something and then press "enter", it doesn't work then if I press "enter" again then it takes the input. how can I solve this problem?
Actually this is working but it works some thing like this code:

Code: Select all

scanf("%s\n",str);