-
August 24th, 2023, 12:46 PM
#1
Hello World C++ 23
Okay -
Very basic question. The following is a simple C++ 23 (or C++ 20) listing. It uses import to pull in iostream. I'm using gcc 13 and want to compile this listing. It doesn't, however, like the import. I tried compiling with the -std=c++2a option, but that didn't help.
Code:
import <iostream>;
using namespace std;
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
Any suggestions on what I might be doing wrong or what I need to do to get this listing to compile using the import? (yeah, I know I can change it to #include, but that defeats the C++ 20/23 usage.
(error is 'import' does not name a type....
-----------------------------------------------
Brad! Jones,
Yowza Publishing
LotsOfSoftware, LLC
-----------------------------------------------
-
August 25th, 2023, 03:47 AM
#2
Re: Hello World C++ 23
I can't comment on gcc as I don't use it. But this is OK with VS2022 as C++23 (preview set for C++ language standard option):
Code:
import std;
int main() {
std::cout << "Hello world\n";
}
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 25th, 2023, 11:35 AM
#3
Re: Hello World C++ 23
D'oh. Thanks. It's amazing what trouble having one little setting wrong can do. Hours down a rabbit hole.
Sometimes a person needs to step back and think simpler. Your post helped me do that, so thanks!
Brad!
-----------------------------------------------
Brad! Jones,
Yowza Publishing
LotsOfSoftware, LLC
-----------------------------------------------
-
August 26th, 2023, 02:35 AM
#4
Re: Hello World C++ 23
Originally Posted by 2kaud
I can't comment on gcc as I don't use it. But this is OK with VS2022 as C++23 (preview set for C++ language standard option):
Code:
import std;
int main() {
std::cout << "Hello world\n";
}
And trying to compile in VS2022 with C++20 causes the similar errors as Brad! with gcc had.
Last edited by VictorN; August 26th, 2023 at 05:21 AM.
Victor Nijegorodov
-
August 26th, 2023, 04:39 AM
#5
Re: Hello World C++ 23
compile in VS2022 with C++20
C++20? So last year!
With modules the standard library will no longer be split into tons of small little headers. Instead you'll just do import std; and that's it. Module support for the standard library is part of C++23 however, not C++20.
There's also std.compat which exports everything in std and also adds the C runtime global namespaces.
Because named modules don't expose macros, macros like assert, errno, offsetof, va_arg, and others aren't available when you import std or std.compat
See:
https://learn.microsoft.com/en-us/cp...?view=msvc-170
Last edited by 2kaud; August 26th, 2023 at 05:30 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 27th, 2024, 08:07 AM
#6
Re: Hello World C++ 23
GCC 13 doesn?t fully support import for standard headers like <iostream> yet. For now, stick with #include <iostream>. Use -std=c++23 for C++23 features, but import <iostream> won?t work until future compiler updates improve module support.
jackinthebox menu.
Last edited by Juliadyer; November 25th, 2024 at 05:25 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|