Concept Flow - String input and output
Start Program
Prompt User for Input
User Types String
Store Input in String Variable
Output the String
End Program
The program starts, asks the user to type a string, stores it, then prints it back.
#include <iostream> #include <string> int main() { std::string name; std::getline(std::cin, name); std::cout << name << std::endl; return 0; }
| Step | Action | Input/Value | Variable 'name' | Output |
|---|---|---|---|---|
| 1 | Program starts | - | - | - |
| 2 | Wait for user input | User types: Hello World | - | - |
| 3 | Store input in 'name' | Hello World | Hello World | - |
| 4 | Print 'name' | - | Hello World | Hello World |
| 5 | Program ends | - | Hello World | - |
| Variable | Start | After Input | Final |
|---|---|---|---|
| name | "" | Hello World | Hello World |
String input and output in C++: - Use std::string to store text. - Use std::getline(std::cin, var) to read full line including spaces. - Use std::cout << var << std::endl; to print the string. - std::cin >> var reads only until first space. - Always include <string> and <iostream> headers.