By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

multiple word error

P: n/a
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,
no*****@wanadoo.be

////////////////////////////////////////////////////
#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;
}
////////////////////////////////////////////////////
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Giovanni Noppe" <no*****@wanadoo.be> wrote...
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


Thanks,

Giovanni Noppe,
no*****@wanadoo.be

////////////////////////////////////////////////////
#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;
}
////////////////////////////////////////////////////

Jul 22 '05 #2

P: n/a


Giovanni Noppe wrote:

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

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.