After dedicating a full time for this Catch 22 , I got the remedy to the problem.
googling , testing ,testing ,testing and testing Is the ultimate recipe in this business (and most definitly in any other field as well)
Hell , This is C++ programming ! you either fire up your compiler and probe the code or you can just rename your title to anything else than a "coder"
well , someone before just asked me to giving him a note when I find a
smarter solution .
wait , should i license that?? ....nah no need...
So here it's , have fun and educate yourselves! :
Code:
#include <iostream>
using namespace std;
int main(){
char x[10];
for(;;)
{
cout<<"Enter Message:";
cin.getline(x,10);
if(cin.fail()){
cin.clear();
//I'm the magic line
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
cin.clear();
cout<<"Message is:"<<x<<endl;
}
return 0;
}
according to the 2003 standard update (and how i hate them)
Edit:
Ooops , someone else just post this before me , should have clicked "post" quicker LOL