input console c++ code example
Example 1: c++ read console input
// Include the library for console in-/outputs
#include <iostream>
// Include the libary for strings
#include <string>
// Main function
int main()
{
// Initialize variable
std::string value;
// Read from console
std::getline(std::cin, value);
}
Example 2: how to get input from the console in c++
int age;
cin >> age;
Example 3: get data from terminal c++
int i;
cout << "Please enter an integer value: ";
cin >> i;
Example 4: c++ output
#include <iostream>
int main(){
std::cout << "Hello World!" << std::endl; // prints "Hello World"
}