Description
g++ -o 01-hellow -std=c++20 01-hellow.cpp on my Linux machine did not work.
The issue with gcc is:
$ g++ -o 01-hellow -std=c++20 01-hellow.cpp
01-hellow.cpp:3:1: error: ‘import’ does not name a type
3 | import std;
| ^~~~~~
01-hellow.cpp:3:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
01-hellow.cpp: In function ‘int main():
01-hellow.cpp:7:5: error: ‘cout’ was not declared in this scope
7 | cout << "Hello, World!" << '\n';
| ^~~~
01-hellow.cpp:1:1: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
+++ |+#include <iostream>
1 | // 01-hellow.cpp : prints a line of text to the console
and with clang is:
$ clang++ -o 01-hellow -std=c++20 -stdlib=libc++ 01-hellow.cpp
01-hellow.cpp:3:8: fatal error: module 'std' not found
import std;
~~~~~~~^~~
1 error generated
I suggest updating the code for people who use linux, vim (or similar editors). A lot of us use the command line.
A quick answer of course is:
// 01-hellow.cpp : prints a line of text to the console
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << '\n';
}
Thanks,