C++ documentation
cppreference is the best quick reference for modern C++ (STL, language features).
cppreference is the best quick reference for modern C++ (STL, language features).
cat > main.cpp <<'EOF'
#include <iostream>
int main(){ std::cout << "hello\n"; }
EOF
c++ -std=c++20 -Wall -Wextra -O2 main.cpp -o app
./app
cmake_minimum_required(VERSION 3.20)
project(app LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
add_executable(app main.cpp)
#include <iostream>
#include <vector>
int main() {
std::vector<int> xs{1, 2, 3};
std::cout << xs.size() << "\n";
}
#include <memory>
auto p = std::make_unique<int>(42);
int i = 1;
auto n = 123; // deduced
const double pi = 3.14;
#include <vector>
std::vector<int> xs{1, 2, 3};
for (const auto &x : xs) {
// ...
}
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
#include <string>
class User {
public:
User(std::string email) : email_(std::move(email)) {}
const std::string& email() const { return email_; }
private:
std::string email_;
};