Skip to content

Introduction

C++ là ngôn ngữ biên dịch, hỗ trợ procedural, object-oriented và generic programming. Nó thường dùng cho hệ thống, game engine, embedded, performance-critical backend và competitive programming. Các compiler phổ biến: GCC/G++, Clang và MSVC.

#include <iostream>
int main()
{
std::cout << "Hello World";
return 0;
}
ToolPlatformCommand
G++Linux, macOS, Windowsg++ main.cpp -std=c++20 -O2 -Wall -o main
Clang++Linux, macOS, Windowsclang++ main.cpp -std=c++20 -O2 -Wall -o main
MSVCWindowscl /std:c++20 /EHsc main.cpp

Compile process: preprocess -> compile -> assemble -> link.

#include <iostream>
#include <string>
int main()
{
std::string name;
std::cin >> name;
std::cout << "Hi, " << name << '\n';
}
  • Quên #include cho thư viện đang dùng.
  • Trộn C++ standard quá cũ với cú pháp C++17/20.
  • Dùng using namespace std; trong header file.

cpp introduction c++ là gì g++ gcc clang msvc compile biên dịch hello world