fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <limits>
  4. #include <vector>
  5. using std::cin;
  6. using std::cout;
  7. using std::endl;
  8.  
  9. int main() {
  10. std::vector<std::string> test;
  11.  
  12. int stopCreatingStudents = 0;
  13. auto delim = decltype(cin)::traits_type::to_int_type('\n');
  14. while (!cin.fail() && stopCreatingStudents != 1) {
  15. std::string name;
  16. std::getline(cin, name);
  17. if (cin.fail())
  18. break;
  19.  
  20. test.push_back(name);
  21.  
  22. cin >> stopCreatingStudents;
  23. cin.ignore(std::numeric_limits<std::streamsize>::max(), delim);
  24. }
  25.  
  26. for (const auto& str: test)
  27. cout << str << endl;
  28. }
Success #stdin #stdout 0s 5592KB
stdin
Ivan Ivanov
0
test test
    0      
foo foo
1
stdout
Ivan Ivanov
test test
foo foo