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

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
User avatar
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

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

Post by CodeMaker » Thu Jan 06, 2005 3:59 pm

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?
Jalal : AIUB SPARKS

tat tvam asi
New poster
Posts: 30
Joined: Sat Nov 30, 2002 1:04 pm

Post by tat tvam asi » Thu Jan 06, 2005 5:49 pm

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.

User avatar
Cahoun
New poster
Posts: 13
Joined: Mon Jan 03, 2005 2:34 pm
Location: Czech Republic
Contact:

Post by Cahoun » Thu Jan 06, 2005 11:29 pm

Try change

Code: Select all

cout<<mystring; 
to

Code: Select all

cout<<mystring<<endl; 
Learn, learn, learn.

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 » Sun Jan 16, 2005 9:55 am

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);

Post Reply

Return to “C++”