Langage C++

L'essentiel du langage C++: syntaxe, fonctions et exemples

std::cout
Flux de sortie standard
C++
std::cout << "Hello, World!" << std::endl;
std::cin
Flux d'entrée standard
C++
int age;
std::cin >> age;
std::cerr
Flux d'erreur standard
C++
std::cerr << "Error: " << strerror(errno) << std::endl;
std::clog
Flux de journalisation standard
C++
std::clog << "Log message" << std::endl;
std::endl
Manipulateur de fin de ligne
C++
std::cout << "Line 1" << std::endl << "Line 2" << std::endl;
std::setw
Définir la largeur du champ
C++
#include <iomanip>

std::cout << std::setw(10) << 42 << std::endl;
std::setprecision
Définir la précision des nombres à virgule flottante
C++
#include <iomanip>

std::cout << std::setprecision(3) << 3.14159 << std::endl;
std::fixed
Utiliser la notation à virgule fixe
C++
#include <iomanip>

std::cout << std::fixed << std::setprecision(2) << 3.14159 << std::endl;
std::scientific
Utiliser la notation scientifique
C++
#include <iomanip>

std::cout << std::scientific << 3.14159e+10 << std::endl;
std::hex
Afficher en hexadécimal
C++
std::cout << std::hex << 255 << std::endl; // affiche "ff"
std::dec
Afficher en décimal
C++
std::cout << std::dec << 0xff << std::endl; // affiche "255"
std::oct
Afficher en octal
C++
std::cout << std::oct << 64 << std::endl; // affiche "100"
std::boolalpha
Afficher les booléens sous forme de texte
C++
std::cout << std::boolalpha << true << std::endl; // affiche "true"