Professional Documents
Culture Documents
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
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
2. What Is C++?
Slobodan Dmitrović 1
(1) Belgrade, Serbia
C++ Standards
C++ is governed by the ISO C++ standard. There are multiple ISO C++
standards listed here in chronological order: C++03, C++11, C++14,
C++17, C++20, and the upcoming C++23 standard.
Every C++ standard, starting with C++11 onward, is referred to as
“modern C++.” And modern C++ is what we will be teaching in this
book.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2023
S. Dmitrović, Modern C++ for Absolute Beginners
https://doi.org/10.1007/978-1-4842-9274-7_3
3. C++ Compilers
Slobodan Dmitrović 1
(1) Belgrade, Serbia
C++ programs are usually a collection of some C++ code spread across
one or multiple source and header files. Source files, by convention,
have the .cpp extension, and header files, by convention, have the .h
extension. Other extensions are also possible. Both header and source
files are regular text files containing some C++ source code. The C++
compiler is a program that compiles these files and turns them into
object files. A linker then links object files together to create an
executable file or a library. At the time of writing, some of the more
popular C++ compilers are
– The g++ front end (as part of the GNU Compiler Collection or GCC)
– Visual C++ (as part of the Visual Studio IDE)
– Clang (as part of the LLVM)
On Linux
To install a C++ compiler (as part of the GCC) on Linux Ubuntu, type the
following inside the terminal:
g++ source.cpp
./a.out
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’s 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()
{
}
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
}
Multiline 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.";
}
Output:
Hello World.
Explanation:
The #include <iostream> statement includes the iostream
header file content into our source file via the #include directive. The
iostream header is part of the standard library. We need its inclusion
to be able to use the std::cout object, also known as the standard
output stream. The << operator, called the stream insertion operator,
inserts our Hello World string literal into that output stream. A 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 located 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:
Another random document with
no related content on Scribd:
R571693.
One Monday morning.
LP42980.
One that got away.
LP43026.
On - Line Software, Inc.
MP25127 - MP25131.
On Scene Cine Films.
MP25357.
On the road with Charles Kuralt.
MP25100.
On the shores of Nova Scotia.
R578945.
Operating systems concepts.
MP24940.
Operating systems features.
MP24942.
Operational considerations.
MP24956.
Operation quickfind.
MP25438.
Operation: Time fuse.
LP43229.
Operation: Wastepaper world.
LP43231.
Op - Op the eskimo and the igloos of OOmy.
LU3664.
Optical isomers.
MP25316.
Optimists.
LP42936.
Optimists of Nine Elms.
LP42936.
Ordeal of a President.
LP43363.
Order in the house.
LP43057.
Organization.
LP43237.
Organization controls in EDP systems.
MP25239.
Organization for Tropical Studies.
MP24969 - MP24974.
Orientation and overview.
MP25449.
Origins of man.
MP24742 - MP24745.
Orson Welles tonight.
MP24878.
MP24880.
Ortho Diagnostics.
MP25355.
Ortho Pharmaceutical Corporation.
MP24848.
Ortho Pharmaceutical Corporation.
SEE Ortho Diagnostics.
Osborn, John Jay, Jr.
LP43261.
OS overview.
MP24940 - MP24945.
OS / VSJCL differences.
MP25132.
Other half of the sky, a China memoir.
MU9015.
Other Martin Loring.
LP43423.
Other side of the coin.
LP43022.
Our way of life.
MP25278.
Our wonderful body: how we keep fit.
MP25391.
Our wonderful body: medicines, drugs and poisons.
MP25395.
Out California way.
R568605.
Outcast.
LP43489.
Outdoor play: a motivating force for learning.
MP25165.
Outlaw of the plains.
R569735.
Out West.
R578428.
Overland riders.
R569733.
Overnight.
MU9004.
Over the Santa Fe Trail.
R572338.
Overview.
MP25162.
Owczarzak, Alfred F.
MP25297.
MP25310.
Owen Marshall, counselor at law.
LP43140 - LP43158.
LP43409 - LP43412.
Oz. of Prevention.
MP25338.
MP25339.
P
Pace Films Productions.
MP25272.
Pal, Laszlo.
MP25040.
Palmer, Patrick.
LP43310.
Palomar Pictures International, Inc.
LP43208.
Pamar, Inc.
MP25180.
Panasia.
LP42939.
P and A facilities.
MU9007.
P and A inventory management.
MU9006.
Pandora’s box.
MP25108.
Paper chase.
LP43261.
Papua and New Guinea.
MP24875.
Paramount news.
R566187.
R566188.
R566924.
R566925.
R567527.
R567767.
R567768.
R568370.
R568652.
R569926 - R569929.
R570570 - R570571.
R570573.
R570577.
R572286.
R572287.
R572755.
R572757.
R572758.
R573105.
R573106.
R573321 - R573323.
R574195 - R574198.
R574924 - R574925.
R575366 - R575367.
R576619 - R576622.
R577329 - R577330.
R578416 - R578417.
R579136 - R579139.
R579724 - R579725.
R579895 - R579896.
Paramount Pictures Corporation.
LP42937.
LP43354 - LP43355.
Paramount Pictures Corporation. Paramount Television.
LP43550 - LP43573.
Paramount Pictures, Inc.
R566187.
R566188.
R566924.
R566925.
R567527.
R567767.
R567768.
R568370.
R568652.
R569926 - R569929.
R570570 - R570571.
R570573.
R570577.
R572286.
R572287.
R572755.
R572757.
R572758.
R573105.
R573106.
R573321 - R573323.
R573497.
R574027 - R574034.
R574195 - R574198.
R574924.
R574925.
R575366.
R575367.
R576594.
R576619 - R576622.
R577329 - R577330.
R578383.
R578390.
R578392.
R578416 - R578417.
R579136 - R579139.
R579724 - R579725.
R579895 - R579896.
Paramount Television, a division of Paramount Pictures Corporation.
SEE Paramount Pictures Corporation. Paramount Television.
Parent counseling child care system.
MP25168.
Park Avenue beat.
LP43386.
Park Avenue rustlers.
LP43395.
Participative problem solving skills.
MP25423.
Parts and accessories facilities.
MU9007.
Parts and accessories inventory management.
MU9006.
Part time pal.
R572724.
Pass.
MP24915.
Passage to Helena.
LP42990.
Pastorale.
R574863.
Patio museum.
R578362.
Patriotic music: its influence on United States history, 1775 - 1900.
MP24799.
Patrol procedures, 1 — violent crimes.
MP24933.
Patterson, Donald D.
MP25114.
Paul, Rodrick.
LP43261.
Paul Revere’s ride.
LP43366.
Pawn.
LP43340.
Peacemaker.
LP43238.
Peace pipe.
LP43163.
Peace time football.
R572099.
Peach Enterprises, Inc.
MP25484.
Pearlstone Film Company.
MP25478.
Pedestrian.
MP24750.
Peiser, Judy.
MP25277.
Pelican pranks.
R572016.
Penguins.
LP43530.
Penn - Pacific Corporation. Sidaris Company.
MP24847.
Pentagon.
LF127.
LF132.
LF135.
LF137.
Peregrinations Film Holding, Ltd.
MU8894.
Perfection of vices.
LP43584.
Personal safety.
MP25233.
Perspective Films, a division of Esquire, Inc. SEE Esquire, Inc.
Perspective Films.
Perugia, Luciano.
LP42961.
Peters, Brock.
LP43138.
Peters, Norman C.
MP25488.
Petersen Company.
LP43138.
Pet peeves.
R579955.
Pfizer, Inc.
MP25125.
MP25154.
MP25169.
MP25324.
MP25385.
MP25386.
MP25417.
MP25427.
Phantom of Hollywood.
LP43210.
Pharmaceutical Division, Marion Laboratories, Inc. SEE Marion
Laboratories, Inc. Pharmaceutical Division.
Phillips, Robert J.
MP25062.
Phony express.
LP43131.
Phos: The Light.
MP24916.
Phototaxis in amoeba and euglena SP.
MP25301.
Physical and chemical properties of the elements.
MP25228 - MP25231.
Physical diagnosis.
MP25254 - MP25268.
Physical properties.
MP25228.
MP25231.
Physiological and behavioral effects of noise.
MP24800.
Piece of God.
LP43147.
Pierce, Albert L.
MP25042.
Pierce, Charles B.
LP43576.
Pierce (Charles B.) Advertising and Productions, Inc.
LP43576.
Pilgrim lady.
R568604.
Pillar, David.
LP43228.
Pine marten getting food.
MP24769.
Pine squirrel: mother and young.
MP24788.
Pinewood Films, Ltd.
LF133.
LF134.
LF135.
LF143.
Pinter, Harold.
LP42934.
Pit.
LP43236.
Pitfall.
LP43578.
Place of our own.
MP25415.
Plainsman and the lady.
R568606.
Plankton to fish: a food cycle.
MP25457.
Plantations of Louisiana.
MP24976.
Plastics.
MP25275.
MP25276.
Plaut, Walter.
MP25298.
MP25307.
Playboy Productions, Inc.
LP43622.
Playground in the zoo.
MU8995.
Plea.
LP42975.
Please don’t send flowers.
LP43463.
Pluto.
LP43536.
Poetry for fun - dares and dreams.
MP25064.
Poet’s pub.
LF136.
Point of proof 800 series cornhead.
MP25156.
Point of proof low profile combine.
MP25157.
Point of proof rotary cultivators.
MP25159.
Point of proof 345 spring tooth harrow.
MP25158.
Political animal.
MP25138.
Pollution Control Education Center, Township of Union Public
Schools. SEE Union Township (NJ) Public Schools. Pollution
Control Education Center.
Polo.
R570079.
Polymorph Films, Inc.
MP24983 - MP24986.
Polynesia.
MP25219.
Ponicsan, Darryl.
LP43260.
Poolside hands.
MU9009.
Portafilms.
LP43126.
MP24862.
MP24938.
MP24939.
Possessed.
LP43234.
Potpourri.
MP25282.
Power steering problems and diagnosis.
MP25146.
Prairie badmen.
R569730.
Prairie raiders.
R578899.
P. R. C. Pictures, Inc.
R569727 - R569733.
R569735 - R569745.
Predators and prey of the forest.
MP24779.
Pressure point.
LP43494.
Preventing laboratory accidents.
MP25294.
Price of a life.
LP43052.
Primal man.
MP25445.
Primary Medical Communications, Inc.
MP24796.
Principles of virtual storage.
MP25133.
Priority one: environment — water pollution, distillation of water.
MP25494.
Problem.
LP43159.
Problem drinkers.
MP25405.
Problem with Charlie.
LP43421.
Processing controls.
MP25238.
Produ Film Company.
LU3669.
Produzioni DeLaurentiis Intermaco, S. P. A.
LP43351.
Professional.
LP43288.
Professor.
LP43171.
Program design and task management.
MP24941.
Programmed for panic.
LP43432.
Programming concepts.
MP24954.
Programming efficiency.
MP25433.
Project Concern, Inc.
MP24917.
Project 7, Inc.
MP24893.
Project Washoe.
MP25170.
Prophet.
LP43253.
Proprioceptive and sensory systems, normal and abnormal signs.
MP25259.
Prostaglandins: tomorrow’s physiology.
LP43123.
Protein translation.
MP25314.
Psychiatry learning system.
MP25378.
Psychological Skills Development Corporation.
MP25425.
Psynfac Corporation.
MP25488.
Public Communication Foundation for North Texas, Dallas.
MP25413.
Public image.
LP43303.
Publicity hound.
LP43183.
Public Media, Inc.
MP24868 - MP24877.
MP25473.
MP25475.
Pupil centered classroom — elementary.
MP25364.
Purge of madness.
LP43114.
Pursued.
LP43242.
R576618.
Q
Q - ED Productions, Inc.
LP43127.
QM Productions.
LP42987 - LP43046.
LP43234 - LP43257.
Quality of fear.
LP43112.
Queen of burlesque.
R569727.
Queens College, Flushing, NY.
MP25165.
Queen’s gambit.
LP42964.
Quest.
MP24902.
Question of guilt.
LP43471.
Quiet campus.
MU8993.
R
Raack, R. C.
MP25181.
Rabbit transit.
R567286.
Raccoon family.
MP24775.
Raccoon getting food.
MP24787.
Raccoon survival techniques.
MP24785.
MP24786.
Radioactive fission.
MP25177.
Radioactivity.
MP25176.
Radnitz, Robert B.
LP43371.
Rainbow over the Rockies.
R579842.
Ramsey (Hec) Productions.
LP43383.
LP43384.
LP43388.
LP43389.
Ramsgate Films.
MP24906.
Rank Film Distributors, Ltd.
R568515.
R574816 - R574819.
R578285 - R578288.
R578604 - R578605.
Rasch, Arthur Robert.
MU8975.
Razor’s edge.
R568008.
Reaching out.
MP25342.
Read.
LP43073.
Reader’s Digest Association, Inc.
LP43233.
Reader’s theater — secondary.
MP25372.
Reading activities.
MP25375.
Reading skills series, no. 3.
MP25269.
MP25270.
Ready.
LP43074.
Ready, set, read.
LP43073.
LP43074.
LP43075.
Really important person.
R567066.
Rebel in white.
LP43292.
Record party.
R578384.
Record ride for the pony express.
LP43367.
Red bicycle.
LP43054.
Red fury.
R574038.
Red hot rangers.
R577229.
Redinger, Donald M.
MU8950.
Reducers and gearmotors.
MP24920.
Reese, John.
LP43604.
Reischauer on Asia.
MP25106.
Reluctant dragon.
LP43543.
Reluctant widow.
LF131.
Rembrandt.
MP25154.
Render safe.
LP43406.
Repairs to air conditioning condensers.
MP25067.
Repix, Inc.
R568600 - R568606.
Reptiles.
MP25216.
Republic Productions, Inc.
R5686OO - R568606.
Requiem for young lovers.