Guest User

Untitled

a guest
Jun 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. istringstream
  2.  
  3. int main()
  4. {
  5. char *InputMain;
  6. InputMain=(char *)malloc(5+1);
  7. cout << "Enter the number : " <<endl;
  8. cin.getline ( InputMain, 5, 'n' ); // Input goes into InputMain
  9. cout << "The number entered is : " << InputMain <<endl;
  10. cin.get();
  11. }
  12.  
  13. string str;
  14. if (!getline(cin, str)) {
  15. cerr << "Something went seriously wrong...n";
  16. }
  17.  
  18. istringstream iss(str);
  19. int i;
  20. iss >> i; // Extract an integer value from the stream that wraps str
  21.  
  22. if (!iss) {
  23. // Extraction failed (or a more serious problem like EOF reached)
  24. cerr << "Enter a number dammit!n";
  25. } else if (i < 1000 || i > 9999) {
  26. cerr << "Out of range!n";
  27. } else {
  28. // Process i
  29. }
  30.  
  31. int i;
  32. cin >> i; // Extract an integer value from cin
Add Comment
Please, Sign In to add comment