Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards 1st Edition Slobodan Dmitrović instant download
Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards 1st Edition Slobodan Dmitrović instant download
https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-c-programming-language-
and-c11-to-c20-standards-1st-edition-slobodan-dmitrovic/
https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-the-c-programming-language-slobodan-
dmitrovic/
https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-the-c-programming-language-dmitrovic-
slobodan/
https://textbookfull.com/product/modern-c-for-absolute-beginners-
a-friendly-introduction-to-the-c-programming-language-2nd-
edition-slobodan-dmitrovic/
Handbook of Macroeconomics, Volume 2A-2B SET 1st
Edition John B. Taylor
https://textbookfull.com/product/handbook-of-macroeconomics-
volume-2a-2b-set-1st-edition-john-b-taylor/
https://textbookfull.com/product/modern-c-for-absolute-
beginners-1st-edition-slobodan-dmitrovic/
https://textbookfull.com/product/modern-c-for-absolute-
beginners-1st-edition-slobodan-dmitrovic-dmitrovic/
https://textbookfull.com/product/c-programming-for-absolute-
beginners-radek-vystavel/
https://textbookfull.com/product/modern-c-for-absolute-beginners-
second-edition-solbodan-dmitrovic/
Slobodan Dmitrović
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
1. Introduction
Slobodan Dmitrović 1
(1) Belgrade, Serbia
Dear Reader,
Congratulations on choosing to learn the C++ programming
language, and thank you for picking up this book. My name is Slobodan
Dmitrović, I am a software developer and a technical writer, and I will
try to introduce you to a beautiful world of C++ to the best of my
abilities.
This book is an effort to introduce the reader to a C++ programming
language in a structured, straightforward, and friendly manner. We will
use the “just enough theory and plenty of examples” approach
whenever possible.
To me, C++ is a wonderful product of the human intellect. Over the
years, I have certainly come to think of it as a thing of beauty and
elegance. C++ is a language like no other, surprising in its complexity,
yet wonderfully sleek and elegant in so many ways. It is also a language
that cannot be learned by guessing, one that is easy to get wrong and
challenging to get right.
In this book, we will get familiar with the language basics first.
Then, we will move onto standard-library. Once we got these covered,
we will describe the modern C++ standards in more detail.
After each section, there are source code exercises to help us adopt
the learned material more efficiently. Let us get started!
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_2
2. What is C++?
Slobodan Dmitrović 1
(1) Belgrade, Serbia
3. C++ Compilers
Slobodan Dmitrović 1
(1) Belgrade, Serbia
C++ programs are usually a collection of C++ code spread across one or
multiple source files. The C++ compiler compiles these files and turns
them into object files. Object files are linked together by a linker to
create an executable file or a library. At the time of the writing, some of
the more popular C++ compilers are:
– The g++ frontend (as part of the GCC)
– Visual C++ (as part of the Visual Studio IDE)
– Clang (as part of the LLVM)
3.1.1 On Linux
To install a C++ compiler on Linux , type the following inside the
terminal:
g++ source.cpp
This command will produce an executable with the default name of
a.out. To run the executable file, type:
./a.out
The same rules apply to the Clang compiler. Substitute g++ with
clang++.
3.1.2 On Windows
On Windows , we can install a free copy of Visual Studio.
Choose Create a new project, make sure the C++ language option is
selected, and choose - Empty Project – click Next and click Create. Go to
the Solution Explorer panel, right-click on the project name, choose
Add – New Item – C++ File (.cpp), type the name of a file (source.cpp),
and click Add. Press F5 to run the program.
We can also do the following: choose Create a new project, make
sure the C++ language option is selected, and choose – Console App –
click Next and click Create.
If a Create a new project button is not visible, choose File – New –
Project and repeat the remaining steps.
© Slobodan Dmitrović 2020
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-6047-0_4
Let us create a blank text file using the text editor or C++ IDE of our
choice and name it source.cpp. First, let us create an empty C++
program that does nothing. The content of the source.cpp file is:
int main(){}
The function main is the main program entry point, the start of our
program. When we run our executable, the code inside the main
function body gets executed. A function is of type int (and returns a
result to the system, but let us not worry about that just yet). The
reserved name main is a function name. It is followed by a list of
parameters inside the parentheses () followed by a function body
marked with braces {}. Braces marking the beginning and the end of a
function body can also be on separate lines:
int main()
{
4.1 Comments
Single line comments in C++ start with double slashes // and the
compiler ignores them. We use them to comment or document the code
or use them as notes:
int main()
{
// this is a comment
}
int main()
{
// this is a comment
// this is another comment
}
Multi-line comments start with the /* and end with the */. They
are also known as C-style comments. Example:
int main()
{
/* This is a
multi-line comment */
}
int main()
{
std::cout << "Hello World.";
}
Believe it or not, the detailed analysis and explanation of this
example is 15 pages long. We can go into it right now, but we will be no
wiser at this point as we first need to know what headers, streams,
objects, operators, and string literals are. Do not worry. We will get
there.
A brief(ish) explanation
The #include <iostream> statement includes the iostream
header into our source file via the #include directive. The iostream
header is part of the standard library. We need its inclusion to use the
std::cout object, also known as a standard-output stream. The <<
operator inserts our Hello World string literal into that output stream.
String literal is enclosed in double quotes "". The ; marks the end of
the statement. Statements are pieces of the C++program that get
executed. Statements end with a semicolon ; in C++. The std is the
standard-library namespace and :: is the scope resolution operator.
Object cout is inside the std namespace, and to access it, we need to
prepend the call with the std::. We will get more familiar with all of
these later in the book, especially the std:: part.
A brief explanation
In a nutshell, the std::cout << is the natural way of outputting data
to the standard output/console window in C++.
We can output multiple string literals by separating them with
multiple << operators:
#include <iostream>
int main()
{
std::cout << "Some string." << " Another
string.";
}
To output on a new line, we need to output a new-line character \n
literal. The characters are enclosed in single quotes '\n'.
Example:
#include <iostream>
int main()
{
std::cout << "First line" << '\n' << "Second
line.";
}
#include <iostream>
int main()
{
std::cout << "First line\nSecond line.";
}
"O-on, on kyllä."
"Minä tiesin sen koko ajan", sanoi Dan. "Tulkaa katsomaan kun isä
näkee erehtyneensä arvostelussaan."
He kiiruhtivat halukkaasti, ehtien juuri kuulemaan, kun Cheyne
lausui: "Minua ilahuttaa kuulla hänestä hyvää, sillä — hän on minun
poikani."
"Yksityisvaunussa, luonnollisesti."
"Kyllä hän kertoi senkin"-, vastasi Cheyne, "ja minä melkein luulen
että se juuri teki hänelle enemmän hyvää kuin mikään muu."
"Ja hän sanoi että Dan oli hänen toverinsa!" huudahti rouva
Cheyne. Dan oli jo tarpeeksi heleänvärinen, mutta hän tuli
kerrassaan tulipunaiseksi, kun rouva Cheyne suuteli häntä
molemmille poskille koko seurueen nähden. Sitten he ohjasivat hänet
keulaan näyttääkseen hänelle kanssia, jolloin hän jälleen puhkesi
kyyneliin ja tahtoi välttämättä mennä alas ja nähdä oikein läheltä
Harveyn makuukojun, ja siellä hän tapasi neekerikokin hellaa
puhdistamassa, ja tämä nyökkäsi hänelle ikäänkuin hän olisi ollut
joku, jonka kohtaamista hän oli tiennyt odottaa vuosikausia. He
koettivat, kaksi aina yhtaikaa, selittää hänelle aluksen jokapäiväisen
elämän kulkua, ja hän istui keulapallin vieressä, hansikoidut kätensä
tahraisella pöydällä, nauraen värähtelevin huulin ja itkien loistavin
silmin.
"Kuka nyt enää saattaa käyttää tätä alusta tämän jälkeen"? sanoi
Pitkä Jack Tom Plattille. "Minusta tuntuu kuin hän olisi muuttanut
tämän kirkoksi."
"Minä voin antaa hänelle suolavettä niin paljon kuin hän haluaa —
kunnes hänestä tulee laivankapteeni."
"Ei niin, vaan minä kaap… otin haltuuni nuo 'Sinisen M:n'
rahtialukset — entisen Morgan & McQuade'n linjan — vasta tänä
kesänä."
Cheyne nyökkäsi.
"Airheart korjaa kyllä sen seikan. Hän saa ensin tehdä pari matkaa
laivapoikana, ja sitten koetamme saada hänet kykeneväksi
vaativampiin tehtäviin. Sopisiko siten, että te pitäisitte hänet
luonanne tämän talven ja minä lähettäisin noutamaan häntä varhain
keväällä? Kyllähän Tyvenmeri on jokseenkin kaukana — —"
"Kun hän oli pikku poika, leikki hän usein kauppapuotisilla, ja minä
toivoin mielessäni että hän seuraisi tuota taipumusta suuremmaksi
tultuaankin. Mutta niin pian kuin hän kykeni melomaan venettä,
ymmärsin minä ettei sitä ollut minulle sallittu."
"Ei se voi olla niin", vakuutti rouva Cheyne tyynesti. "Täällä ei ole
yhtään naista, joka omistaisi sadan dollarin arvoisen puvun. Meillä
taas…"
"Kyllä tiedän, äiti kulta. Meillä on — tietysti meillä on. Minä luulen
että pukeutumis-muoti täällä Idässä on sellainen. Viihdytkö hyvin?"
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com