c++ output code example

Example 1: how to output text in c++

std::cout << " Something ";

Example 2: how to grab all of user input c++

// cin with strings
#include 
#include 
using namespace std;

int main ()
{
  string mystr;
  cout << "What's your name? ";
  getline (cin, mystr);
  cout << "Hello " << mystr << ".\n";
  cout << "What is your favorite team? ";
  getline (cin, mystr);
  cout << "I like " << mystr << " too!\n";
  return 0;
}

Example 3: how to print in c++

#include 

int main() {
  std::cout << "Hello World!"; //cout keyword prints "Hello World!"
  return 0;
}

Example 4: how to cout in c++

std::cout << "Hello World!" << std::endl; //Or you can do
std::cout << "Hello World!" <<; //Only in some scenarios

Example 5: get data from terminal c++

int i;
  cout << "Please enter an integer value: ";
  cin >> i;

Example 6: c++ output

#include 

int main(){
  std::cout << "Hello World!" << std::endl; // prints "Hello World"
}

Tags:

Misc Example