Hello World (Pre C++20)
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
You can compile and run this program as follows, for example, using gcc on Linux or other Unix-like platforms.
$ g++ hello-world.cpp
$ ls
a.out hello-world.cpp
$ ./a.out
Hello, World!
Hello World Program in C++20 (Using Modules)
import <iostream>;
int main() {
std::cout << "Hello World!";
return 0;
}
You can compile and run this program, for example, as follows on Linux or other Unix-like platforms.
$ g++ -std=c++20 -fmodules-ts -x c++-system-header iostream
$ g++ -std=c++20 -fmodules-ts hello-world.cpp
$ ls
a.out gcm.cache hello-world.cpp
$ ./a.out
Hello World!
What's Next
If you are interested in learning C++20 programming, then go ahead and set up a development environment.
- Next Step: C++ development environment setup
C C# Clojure Crystal D Dart Erlang F# Go Haskell Java Javascript Julia Kotlin Lua Python Rust Scala Swift Typescript