Loading...

C++ Output

This page adds a second writing line under the word you already have. The comments page left pine.cpp with one note, // the word stays pine, and ./pine showed only pine. The note did not print. You keep that note and that first line. Under them you add a line that writes cone. Rebuild with the same command. The screen is two lines: pine, then cone. Getting Started keeps pine.cpp and the lowercase word pine until a later page says the example changed. cone is the new second line, not a new file.
The compiler is already on the machine. If g++ or clang++ cannot be found, that gap is the install page. The next page is variables. It gives a word a name you can reuse. This page stops before any name. Both words stay inside quotes.

A writing line is a statement the program runs. The first one is unchanged: std::cout << "pine" << std::endl; The second one is new: std::cout << "cone" << std::endl; Each << sends the next piece to the same stream. Each std::endl ends the line, so cone does not sit on the same line as pine. The comment stays above both, on its own line, and the compiler still skips it. return 0; stays under both writing lines and still prints nothing. main is still a free function. There is still no class named Pine.
Type the file in that order, or add only the cone line if the comments file is already on disk. The name on disk stays pine.cpp. Do not add a third writing line.

pine.cpp writes pine and then cone

cpp
#include <iostream>

int main()
{
    // the word stays pine
    std::cout << "pine" << std::endl;
    std::cout << "cone" << std::endl;
    return 0;
}

Rebuild from the folder that holds pine.cpp. The command is g++ -std=c++17 pine.cpp -o pine and then ./pine. If g++ is missing and clang++ is the compiler you installed, swap only the tool name: clang++ -std=c++17 pine.cpp -o pine. The screen is:
pine
cone
The first line is the word the comments page already showed. The second line is cone, four letters, all lowercase, no space. Count them: c, o, n, e. The first line is still p, i, n, e. The note "the word stays pine" is still absent. The slashes are absent. Nothing from the comment row of the table is printed between the two words. If you see the note on the screen, it was typed inside quotes. The checked note is after //, not inside the writing quotes. If a blank line appears between pine and cone, an extra std::endl was typed. The checked file has one endl on each writing line, so the words stack with no blank line between them.
Delete the cone line, rebuild, and ./pine shows only pine. That is the comments page again. Put the cone line back under the pine line. Swap the two writing lines and the screen becomes cone, then pine. That is a different order. Put pine back on top. The checked order is pine, then cone.

📊 Two lines and the note that stays hidden

Piece What you should see
First pine
Second cone
Note // the word stays pine
Screen pine then cone

std::endl is what splits the two words onto two lines. Remove the first std::endl, so the pine line is std::cout << "pine"; and leave the cone line as it is. Rebuild. The screen is one line, pinecone, because nothing ended the line between the words. No space appears unless you typed a space inside the quotes. Put std::endl back on the pine line. Rebuild. The screen is pine, then cone, on two lines again. Do not leave the endl off.
The second endl ends the cone line. Removing only that one still shows pine and cone on two lines, and the cursor sits at the end of cone instead of on a fresh line. The checked file keeps both endl calls so each word owns a line. A semicolon still ends the statement. It is not a screen character. The quotes still stay in the file.

Three edits throw the screen off, and then you undo them. Comment out the cone line with // at the start of that line. The compiler skips it, the way it skips the note. ./pine shows only pine. Delete those slashes. Change the quoted cone to Cone. The second line becomes Cone. Put the lowercase word back. Remove std:: from the second cout. The build fails, and you get no two-line screen. Put std:: back.
Do not store either word in a name. A name would let you write the word once and reuse it. That is the variables page. Here the words are literals, typed again inside quotes each time you want them on the screen. pine is typed in the first pair of quotes. cone is typed in the second pair. There is no third pair. Do not read the keyboard. Do not add a third line. Do not rename the file. Getting Started still compiles this pine.cpp, still hides the note, and now expects two lines.

The next page is variables. Its job is a name for a word, so the quotes are not the only place the word lives. You might later write the word once, store it, and send that stored word to std::cout. This page does not do that. There is no name, no type, and no place where pine or cone is stored outside the quotes. This page stops before that name. You leave with the comment still unprinted, the pine line still first, the cone line still second, and ./pine showing those two lines. You do not leave with a variable. If the screen has a third line, delete the extra writing line before you leave. Two lines is the whole result.
Last pass: the note is // the word stays pine, the first write is pine, the second write is cone, both lines end with std::endl, return 0 prints nothing, the build is g++ -std=c++17 pine.cpp -o pine, and ./pine shows pine then cone. Count the lines on the screen before you leave. There are two, not one and not three. The file name on disk stays pine.cpp. The variables page is next, and this page does not start it.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
4
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 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