#include "stdafx.h"
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
int getInt()
{
int y;
string line;
stringstream input;
while(true){
getline(cin,line);
input.write(line.c_str(),10);
if(input>>y)
return y;
cout<<"Error, try again."<<endl;
input.seekp(ios_base::beg);
input.seekg(ios_base::beg);
}
}
As you can see I'm trying to read an int from cin...Whenever I input a wrong value like "asdfasd" it won't accept any correct value after that.
Edited by Alexander, 01 February 2011 - 05:28 PM.
Corrected <code> in to [code]


Sign In
Create Account


Back to top









