fork download
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int idx;
  9. string title;
  10.  
  11. cout << "Book index? " << endl;
  12. cin >> idx;
  13.  
  14. cout << "Book title? " << endl;
  15. cin >> title;
  16.  
  17. cout << "index: " << idx << ", title: " << title << endl;
  18. cout << "Oops, a part of the title is lost" << endl;
  19.  
  20. // clean up
  21. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  22.  
  23. cout << "Book index? " << endl;
  24. cin >> idx;
  25.  
  26. cout << "Book title? " << endl;
  27. getline(cin, title);
  28.  
  29. cout << "index: " << idx << ", title: " << title << endl;
  30. cout << "Oops, whole title is lost" << endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3432KB
stdin
1
Study in Scarlet
2
Sign of Four
stdout
Book index? 
Book title? 
index: 1, title: Study
Oops, a part of the title is lost
Book index? 
Book title? 
index: 2, title: 
Oops, whole title is lost