Programming Windows: Hello, C++ (Premium)

C++ was created by Bjarne Stroustrup as an object-oriented extension to the C programming language. Stroustrup began his work on the language, which was initially called “C with Classes” in a nod to a foundational object-oriented programming (OOP) concept, the class, in the late 1970s. But over time, he changed the name to C++, where “++” represents the increment operator in C. So C++ is “C plus 1,” or, more loosely, “the next C.”

As you may recall, in the book The C Programming Language, authors Brian Kernighan and Dennis Ritchie (the latter of which invented C) created a simple introductory program called hello, world that showed off some key aspects of that language. It looks like so:
#include <stdio.h>

main()
{
    printf("hello, world\n");
}
In keeping with this tradition, Stroustrup published his own book called The C++ Programming Language to describe his creation in 1985. And he also wrote a similar introductory application for his own book and language which he called Hello, World!. It looks like this:
#include <iostream>

int main()
{
    std::cout << "Hello, World!\n";
}
This code is, I think, less readable than the C version of hello, world. But I assume that even non-programmers, looking past some of the less obvious bits, can see that this application would print the words Hello, World! to the screen. And so it did.

And still does. This program, just like the original C version of hello, world, works today with the latest version of Microsoft Visual C++, part of Visual Studio 2019, without requiring any changes. To check this, I used the same methods as I did previously in Programming Windows: Hello, World (Premium). I created a file called hello.cpp with Notepad, saved it to the desktop, and created an executable file called hello.exe using the command line version of the Visual C++ compiler and linker.

Like so.

Then, I typed hello and tapped Enter. The words Hello, World! appeared as expected. Fun.

I promised not to teach you how to program, and I won’t. But a quick look at this short code block, and how it differs from straight C, might be of interest.

Syntactically, things changed quite a bit between C and C++. This is because C++ uses objects to handle even basic functionality, such as input and output to a console.
#include <iostream>
That said, the #include preprocessor directive works as it did in C: It takes every line of code in the included library, now called iostream, and combines it with the current source code file. And while iostream does for C++ what stdio.h does for C---it is the language’s standard library for input and output, since this functionality is not built-in to the core language---it is object-oriented in nature and not just a flat list of functions.
std::cout << "Hello, World!\n";
On that note, though cout (“see out”) is an object, it performs similarly to printf, a basic function, in C: It repre...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC