C++ Introduction
This page opens the C++ course. The job is to read one file and name the one word on the screen. The file is pine.cpp. The word is pine. Getting Started starts with that file, and this course has no earlier C++ page, so there is no leftover program to delete or rename. The next page will install a compiler and run the file. This page stops before those install commands. When you leave, you should be able to point at the writing line and say the screen shows pine, in lowercase, with the quotes left in the file and no second line of text.
The screen here means the console: a text window, not a drawn window. One line of text, then the cursor on the next line. The four characters are p, i, n, and e. There is no file name on that line, no function name, and no number. If you picture a second line, you are picturing a different file. This file writes once.
C++ is a compiled language. A compiler reads pine.cpp and builds a program you can run. This course stays with small console programs in C++17. It is not a window toolkit, not a game engine, and not the separate C course. The file below is the whole program for today. It has an include, a function named main, one writing line, and a return. main is a function. It is not a class, and there is no class named Pine. The word pine lives inside quotes on the writing line. Getting Started keeps pine.cpp and that same lowercase word while this module continues, until a later page says the example changed.
You do not need a newer language level to read these lines. You do not need a library beyond the standard one this file includes. The file is short on purpose. Every token in it is part of today's job: the include, the function, the stream, the quoted word, the line ending, and the return. Anything you do not see in the file is not on this page.
#include <iostream>
int main()
{
std::cout << "pine" << std::endl;
return 0;
}
Read the file from the top. The first line is #include
int main() is the start of the program. The parentheses are empty because this page passes no arguments. The braces hold the two statements that run. The word main is not printed. The braces are not printed. The indent inside the braces is only for your eyes. The compiler does not turn those spaces into screen characters.
std::cout << "pine" << std::endl; is the writing line. std::cout is the standard output stream. The prefix std:: means the name belongs to the standard library. This file does not contain a using directive, so the prefix stays on the name. The operator << sends the next piece to that stream. The first piece is the quoted word pine. The quotes are part of the file. They are not part of the screen. std::endl ends the line. It is not a second word on the screen. The semicolon ends the statement. It is not a screen character.
return 0; tells the system the program finished in the normal way. The number 0 is a status. It is not printed under pine. If you run this file after the next page installs a compiler, the screen is exactly one line:
pine
Several tokens look important and still stay off the screen. The file name pine.cpp is how you store the program. The token main is the function the compiler looks for. The prefix std:: is how you spell the library name. The number 0 after return is a status. None of those appear as text. The only visible result is the lowercase word pine on its own line. If the writing line said "Pine" with a capital P, the screen would be Pine. This file uses the lowercase word, so the screen is pine.
📊 What pine.cpp puts on the screen
| Piece | What this file does with it |
|---|---|
| File | pine.cpp stores the program and is not printed |
| Entry | int main() starts the program and is not printed |
| Write | std::cout << "pine" << std::endl; sends the word |
| Screen | pine |
Three small edits change the result, and then you put the file back. Remove std:: from cout and the compiler does not know the bare name cout, so the file does not compile and there is no screen. Remove the quotes around pine and the compiler treats pine as a name that was never declared, so again there is no screen. Change the quoted word to "Pine" and the screen becomes Pine. Leave the file as it is written and the screen stays pine.
Do not add a line that says using namespace std;. The file is meant to show the prefix on cout and on endl. Do not add a second writing line. One word is the whole result. Do not replace std::cout with printf. Do not replace it with Console.WriteLine. Those calls belong to other courses, and they are not in pine.cpp. Do not wrap main inside a class. A class wrapper would make this a different program, and the screen check on this page would no longer match the file you were given.
Put every experiment back before you judge the screen. The checked file has the include, the empty main, the one writing line with the lowercase word, the line ending, and return 0. Anything else is a different file. A different file can be useful later. It is not the file this page checks.
People arriving from another language sometimes hunt for a class wrapped around main, or for a capital Main, or for a window that opens beside the console. This file has none of those. The program starts at the free function main. The only output tool on this page is std::cout and the operator <<. The left side is the stream. The right side is the quoted word. Together they write pine.
This course will later add variables, input, types, functions, and classes. None of that is in pine.cpp today. A variable would give the word a name you can reuse. Input would read a line you type. A class would group data and functions. Those pages have their own files and their own jobs. Today the word is a literal, the program does not read the keyboard, and there is no class.
C++17 is the language level for the examples. You do not need a newer standard to read this file. You also do not need a framework. A framework would pull in windows, widgets, or a scene. pine.cpp is a console file. The screen is a text line. If a tool offers you a project wizard, a form designer, or a game template, close it and come back to this file. The lesson is the six lines, not the wizard.
The next page will install a compiler. Its job is Install C++: put g++ or clang where the machine can find it, then run pine.cpp so the word pine shows up. This page stops before those install commands. It does not ask you to type g++, clang, or a package-manager line. It does not ask you to set a path. When you leave, pine.cpp still holds one writing line, the screen word is still pine, and the compiler is still not installed. Install C++ is the next job. This page stops before it.
Last pass: the include brings in iostream, main is a function, std::cout writes the quoted word, std::endl ends the line, return 0 prints nothing, and the screen is pine. Getting Started keeps pine.cpp and that word. The next page will install the compiler. If the screen you imagine has a second line, a capital P, a printed 0, or the file name, go back to the writing line and read the quotes again. The quotes hold pine. The screen shows pine.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top