cpp print string code example

Example 1: print in cpp

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  return 0;
}

Example 2: c++ print

cout << "put text here"

Example 3: c++ print

cout << "hello world"

Example 4: c++ input from terminal when program is called

#include <iostream>
#include <string>

int main( int argc, char* argv[] )
{
    std::string my_arg;

    // First argument is always the name of your program
    std::cout << argv[0] << std::endl;

    if( argc == 2 )
    {
        // Something has been passed in
        my_arg = argv[1];
        std::cout << "Argument passed in is " << my_arg << std::endl;
    }

    return 0;
}

Example 5: how to print string data type in c++

printf("%s\n",someString.c_str());

Example 6: c++ cout int

#include <iostream>

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

Tags:

Cpp Example