02 Preparation
02 Preparation
Programming
2. Preparation
Federico Busato
2024-04-10
Table of Contents
4 How to compile?
5 Hello World
I/O Stream
1/22
Books and
References
Suggested Books
2/22
More Advanced Books
Tutorials:
• Learn C++
• Tutorials Point C++
• en.wikibooks.org/wiki/C++
• yet another insignificant...programming notes
Other resources:
• stackoverflow.com/questions/tagged/c++
4/22
* The full C++ standard draft can be found at eel.is/c++draft/full (32 MB!)
References 3/3
News:
• isocpp.org (Standard C++ Foundation)
• Reddit C++
• cpp.libhunt.com/newsletter/archive
• MeetingCpp Blogroll
Main conferences:
• cppcon.org (slides), (search engine)
• meetingcpp.com (slides)
• isocpp.com conference list
Coding exercises:
• HackerRank C++
• leetcode.com/problemset/algorithms
• open.kattis.com 5/22
Slide Legend
Slide Legend 1/2
⋆
Advanced Concepts. In general, they are not fundamental. They can be
related to very specific aspects of the language or provide a deeper
exploration of C++ features.
A beginner reader should skip these sections/slides
⇝ See next. C++ concepts are closely linked, and it is almost impossible to
find a way to explain them without referring to future topics. These slides
should be revisited after reading the suggested topic
6/22
Slide Legend 2/2
7/22
What Editor/
IDE/Compiler
Should I Use?
What Compiler Should I Use?
9/22
Install the Compiler on Windows
Clang on Windows
Two ways:
• Windows Subsystem for Linux (WSL)
• Run → optionalfeatures
• Select Windows Subsystem for Linux , Hyper-V ,
Virtual Machine Platform
• Run → ms-windows-store: → Search and install Ubuntu 22.04 LTS
• Clang + MSVC Build Tools
• Download Build Tools per Visual Studio
• Install Desktop development with C++ 10/22
What Editor/IDE/Compiler Should I Use? 1/3
• Vim
• Emacs
• NeoVim (link)
• Helix (link)
Not suggested: Notepad, Gedit, and other similar editors (lack of support for
programming)
12/22
What Editor/IDE/Compiler Should I Use? 3/3
14/22
*except for very minor deprecated features
C++ Standard 1/2
15/22
en.cppreference.com/w/cpp/compiler support
C++ Standard 2/2
16/22
Hello World
Hello World 1/2
printf cout
prints on standard output represents the standard output stream
17/22
Hello World 2/2
The previous example can be written with the global std namespace:
#include <iostream>
Note: For sake of space and for improving the readability, we intentionally omit the
std namespace in most slides
18/22
I/O Stream (std::cout) 1/3
C:
#include <stdio.h>
int main() {
int a = 4;
double b = 3.0;
char c[] = "hello";
printf("%d %f %s\n", a, b, c);
}
• Type-safe: The type of object provided to the I/O stream is known statically by the
compiler. In contrast, printf uses % fields to figure out the types dynamically
• Less error prone: With I/O Stream, there are no redundant % tokens that have to
be consistent with the actual objects passed to I/O stream. Removing redundancy
removes a class of errors
• Extensible: The C++ I/O Stream mechanism allows new user-defined types to be
passed to I/O stream without breaking existing code
• The %c conversion specifier does not automatically skip any leading white space:
scanf("%d", &var1);
scanf(" %c", &var2);
21/22
std::print
int main() {
std::print("Hello World! {}, {}, {}\n", 3, 4ll, "aa");
// print "Hello World! 3 4 aa"
}
This will be the default way to print when the C++23 standard is widely adopted
22/22