fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. template<typename T>
  5. T get(const std::string &prompt, T ret = T())
  6. {
  7. std::cout << prompt;
  8. std::cin >> ret;
  9. return ret;
  10. }
  11.  
  12. std::string get(const std::string &prompt)
  13. {
  14. std::cout << prompt;
  15. std::string ret;
  16. std::getline(std::cin, ret);
  17. return ret;
  18. }
  19.  
  20. int main() {
  21. get<int>("int: ");
  22. get<std::string>("string: ");
  23. }
Success #stdin #stdout 0s 4508KB
stdin
Standard input is empty
stdout
int: string: