fork(1) download
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5. string input;
  6.  
  7. void enterstring() {
  8. cout<<"\nEnter input: ";
  9. getline(cin,input);
  10. }
  11.  
  12. void displaystring() {
  13. cout<<"\nyour string is "<<input<<endl;
  14. }
  15.  
  16. int main() {
  17.  
  18. int choice=0;
  19. while(choice!=3) {
  20.  
  21. cout<<"Enter choice: ";
  22. cin>>choice;
  23. switch(choice) {
  24. case 1: enterstring();
  25. break;
  26. case 2: displaystring();
  27. break;
  28. case 3: cout<<"\nQuit";
  29. break;
  30. default: cout<<"\ninvalid choice try again";
  31. }
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0.02s 2684KB
stdin
1
2
1
3
stdout
Enter choice: 
Enter input: Enter choice: 
your string is 
Enter choice: 
Enter input: Enter choice: 
Quit