Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- istringstream
- int main()
- {
- char *InputMain;
- InputMain=(char *)malloc(5+1);
- cout << "Enter the number : " <<endl;
- cin.getline ( InputMain, 5, 'n' ); // Input goes into InputMain
- cout << "The number entered is : " << InputMain <<endl;
- cin.get();
- }
- string str;
- if (!getline(cin, str)) {
- cerr << "Something went seriously wrong...n";
- }
- istringstream iss(str);
- int i;
- iss >> i; // Extract an integer value from the stream that wraps str
- if (!iss) {
- // Extraction failed (or a more serious problem like EOF reached)
- cerr << "Enter a number dammit!n";
- } else if (i < 1000 || i > 9999) {
- cerr << "Out of range!n";
- } else {
- // Process i
- }
- int i;
- cin >> i; // Extract an integer value from cin
Add Comment
Please, Sign In to add comment