C++ Introduction
C++ is a programming language used to write programs. A program is a set of instructions that a computer follows.
A first program
This program has the basic shape of every program in this course. It prints one line of text.
#include <iostream>
int main() {
std::cout << "My first C++ program\n";
return 0;
}Two prints in order
Two print lines run in order. The first line prints before the second line.
#include <iostream>
int main() {
std::cout << "First line\n";
std::cout << "Second line\n";
return 0;
}Example
#include <iostream>
int main() {
std::cout << "C++ is a programming language\n";
std::cout << "C++ programs run on many computers\n";
std::cout << "C++ code is written as plain text\n";
return 0;
}Key points
- C++ code is written as plain text in a file.
- A compiler is a tool that turns code into a form a computer can run.
- The #include <iostream> line brings in tools for printing text.
- int main() is the starting point of the program.
- std::cout prints text to the screen.
In this example, three print lines run in order. The first line says C++ is a programming language. The second line says C++ programs run on many computers. The third line says C++ code is written as plain text.
Note
File names for C++ code often end in .cpp.
Try it Yourself
Edit the code, then press Run.
Running is simulated Β· Programiz C++ Compiler
Exercise
Which line prints text to the screen?