c++ print integer code example

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

// cin with strings
#include <iostream>
#include <string>
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 2: how to print integer in c++

#include <iostream>
using namespace std;

int main()
{    
    int number;

    cout << "Enter an integer: ";
    cin >> number;

    cout << "You entered " << number;    
    return 0;
}

Example 3: c++ cout int

#include <iostream>

std::cout << "Hello, World!" << std::endl;

Example 4: how to print all numbers in an integer in c++

#include<iostream>
using namespace std;
void print_each_digit(unsigned long long int x)
{
    if(x >= 10)
       print_each_digit(x / 10);

    int digit = x % 10;

    cout << digit << '\n';
}
int main(){
	unsigned long long int i;
	cin >> i;
	print_each_digit(i);
	return 0;
}

Tags:

C Example