fork download
  1. // If you are not sure what some lines of code do, try looking back at
  2. // previous example programs, notes, or ask a question.
  3.  
  4. // Remember to include iostream when using console IO
  5. #include <iostream>
  6.  
  7. // Also remember to include this line (or type std:: each time)
  8. using namespace std;
  9.  
  10. int main() {
  11.  
  12. int input;
  13.  
  14. // This line outputs the text "Basic IO Examples" to the screen,
  15. // and creates an empty line below it. Note that there are two
  16. // "endl" statements: one ends the line that includes the text,
  17. // and the other creates an empty line below it.
  18. cout << "Basic IO Examples" << endl << endl;
  19.  
  20. // This line outputs a prompt for the user to enter an integer.
  21. // Note that there are no endlines at all, so that the user will
  22. // enter the number on the same line as the prompt.
  23. cout << "Enter an integer: ";
  24.  
  25. // This line allows the user to input a value, and once they press
  26. // enter, it puts the value into the variable "input." Note that
  27. // this automatically ends the line.
  28. cin >> input;
  29.  
  30. // Finally, this line outputs another empty line, and then text
  31. // describing the output, and then input variable, which
  32. // holds the user's input. It them ends the line and outputs
  33. // one more empty line.
  34. cout << endl << "User input: " << input << endl << endl;
  35.  
  36. // As seen previously, this line holds the screen for the user.
  37. // once they press a key, the program will end.
  38. system("pause");
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout #stderr 0s 3416KB
stdin
1234
stdout
Basic IO Examples

Enter an integer: 
User input: 1234

stderr
sh: 1: pause: not found