Skip to content

compiling 01_hellow.cpp #2

Closed
Closed
@rinka-meltiron

Description

@rinka-meltiron

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions