getline

From: slurper (slurper1234_at_hotmail.com)
Date: 04/14/04


Date: Wed, 14 Apr 2004 15:38:24 +0200

what's wrong with this program:

#include <iostream>
#include <string>
using namespace std;

int main()
{
  string string1, string2;
  
  cout << "Type a word: ";
  cin >> string1;
  cout << "You typed: " << string1 << endl;

  cout << "now type a line: ";
  getline( cin, string2 ); <-------- doesn't wait for me here
  cout << "you typed: " << string2 << endl;

  return 0;
}

it compiles but when run it doesn't wait for me to enter a sentence at the
getline command

output:
Type a word: lol
You typed: lol
now type a line: you typed:

platform: mandrake linux using g++ on i386



Relevant Pages

  • Re: Errors in compilation of simple programme
    ... using namespace std; ... cin>> i; ... it compiles without a problem on Visual C++ ... int main ...
    (microsoft.public.vc.language)
  • Re: Errors in compilation of simple programme
    ... using namespace std; ... cin>> i; ... it compiles without a problem on Visual C++ ... int main ...
    (microsoft.public.vc.language)
  • Re: problem with rand()
    ... > Using gcc, this compiles, runs, and outputs as expected, but on ... > using namespace std; ... > int main ...
    (comp.lang.cpp)
  • Re: getline
    ... > using namespace std; ... > int main ... > the getline command ... > Type a word: lol ...
    (comp.lang.cpp)
  • Re: mem_fun vs mem_fun_ref
    ... However this compiles: ... > int main ... > using namespace std; ... > A obj; ...
    (comp.lang.cpp)