Created
October 31, 2009 23:29
-
-
Save raek/223308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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