fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int ActionGenerator() {
  8. int Action;
  9. string Input = "";
  10. while(true) {
  11. cout << endl << "SELECIONE UMA ACTION: " << endl;
  12. cout << "[1 = ActionX]" << endl << "[2 = ActionZ]" << endl;
  13. getline(cin, Input);
  14. stringstream myStream(Input);
  15. if ((myStream >> Action) && (Action == 1 || Action == 2)) return Action;
  16. else cout << endl << "ACTION INVALIDA !" << endl;
  17. }
  18. }
  19.  
  20. int main() {
  21. cout << ActionGenerator() << endl << "ok" <<endl;
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/41855/101
Success #stdin #stdout 0s 15240KB
stdin
abc
12
1
stdout
SELECIONE UMA ACTION: 
[1 = ActionX]
[2 = ActionZ]

ACTION INVALIDA !

SELECIONE UMA ACTION: 
[1 = ActionX]
[2 = ActionZ]

ACTION INVALIDA !

SELECIONE UMA ACTION: 
[1 = ActionX]
[2 = ActionZ]
1
ok