multiple word error

G

Giovanni Noppe

Hello,

I'm writing a program, but I've got a question. I wrote a simple program
that explains my problem. First you must give in an integer and next you
must give a string containing multiple words. If I put an integer in my
variable that is okay, but I have to hit enter twice instead of once for my
string. Is there someone who knows how I can solve this problem ?

Thanks,

Giovanni Noppe,
(e-mail address removed)

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

void main()
{
int getal;
string zin;
cout<<"Integer : ";
cin>>getal;
cin.ignore(255,'\n');
cin.clear();
cout<<"String : ";
getline(cin,zin);
cout<<"\n\n\n";
cout<<getal<<endl;
cout<<zin;
}
////////////////////////////////////////////////////
 
V

Victor Bazarov

Giovanni Noppe said:
I'm writing a program, but I've got a question. I wrote a simple program
that explains my problem. First you must give in an integer and next you
must give a string containing multiple words. If I put an integer in my
variable that is okay, but I have to hit enter twice instead of once for my
string. Is there someone who knows how I can solve this problem ?

Get a better version of the standard library. See www.stlport.org
 
K

Karl Heinz Buchegger

Giovanni said:
Hello,

I'm writing a program, but I've got a question. I wrote a simple program
that explains my problem. First you must give in an integer and next you
must give a string containing multiple words. If I put an integer in my
variable that is okay, but I have to hit enter twice instead of once for my
string. Is there someone who knows how I can solve this problem ?

Any chance you are using VC++ 6.0?
This (or a very similar) behaviour is a documented bug with that compiler.
For fixes see: http://www.dinkumware.com/vc_fixes.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,378
Latest member
BlakeLig

Latest Threads

Top