Skip to content

Instantly share code, notes, and snippets.

@raek
Created October 31, 2009 23:29
Show Gist options
  • Save raek/223308 to your computer and use it in GitHub Desktop.
Save raek/223308 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
vector<double> v;
while(cin)
{
string line;
getline(cin, line);
istringstream iss(line);
double number;
iss >> ws;
if (iss.eof())
{
cout << "tom rad" << endl;
return 0;
}
iss >> number;
if (iss.fail())
{
cout << "ej giltigt tal" << endl;
continue;
}
iss >> ws;
if (iss.eof())
{
v.push_back(number);
cout << "korrekt inläsning: " << number << endl;
}
else
{
cout << "data kvar på raden" << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment