C++ Output (Print Text)

In C++, you can show text and values on the screen using the cout object and the << (insertion operator). This is essential for communicating with users and displaying information in programs.



Basic Output Example

When printing text in C++, always enclose the content within double quotes (" "):

#include <iostream>
using namespace std;

int main() {
  cout << "Revving up the engine!";
  return 0;
}




Multiple Output Statements

You can include multiple cout statements in a program. However, they do not automatically create new lines:

#include <iostream>
using namespace std;

int main() {
  cout << "Revving up the engine!";
  cout << " Time to hit the road!";
  return 0;
}

Explanation:

  • First statement: Prints "Revving up the engine!"
  • Second statement: Immediately prints " Time to hit the road!" on the same line.
  • Since there is no automatic line break, the output appears next to each other without separation.
Scroll to Top