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