Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I think there may be something wrong with my gcc and g++ install because this code below will not run on my computer.

#include <iostream>
#include <numbers>

int main()
{
    long double pi {0};
    long double pi2 {0};

    pi  = std::numbers::pi_v<long double>;
    pi2 = std::numbers::pi_v<long double>;

    std::cout << pi << std::endl << pi2;

}

How can I do a full reinstall on gcc and g++? Also, how do I make sure CodeBlocks is using this reinstalled version.

EDIT: running g++ version 11.1.0 & using the -std=c++20 this is the error message that appears:

g++ randomCodeWhileReading.cpp -o -std=c++20
randomCodeWhileReading.cpp: In function ‘int main()’:
randomCodeWhileReading.cpp:9:16: error: ‘std::numbers’ has not been declared
    9 |     pi  = std::numbers::pi_v<long double>;
      |                ^~~~~~~
randomCodeWhileReading.cpp:9:30: error: expected primary-expression before ‘long’
    9 |     pi  = std::numbers::pi_v<long double>;
      |                              ^~~~
randomCodeWhileReading.cpp:10:16: error: ‘std::numbers’ has not been declared
   10 |     pi2 = std::numbers::pi_v<long double>;
      |                ^~~~~~~
randomCodeWhileReading.cpp:10:30: error: expected primary-expression before ‘long’
   10 |     pi2 = std::numbers::pi_v<long double>;
      |                              ^~~~
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
312 views
Welcome To Ask or Share your Answers For Others

1 Answer

Please: ALWAYS copy/paste your error message when you post a question!

I suspect this is the compile error you're getting:

x.cpp:2:10: fatal error: numbers: No such file or directory
 #include <numbers>

The header is only available since C++20: https://en.cppreference.com/w/cpp/numeric

Q: Do you have a C++20-compatible version of G+? You can determine this using g++ --version

Q: Are you compiling for C++ 20 (e.g. -std=c++20)?

Here is the Gnu C++ documentation for C++ 20 compatibility:

https://gcc.gnu.org/projects/cxx-status.html

C++20 Support in GCC GCC has experimental support for the latest revision of the C++ standard, which was published in 2020.

C++20 features are available since GCC 8. To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line. Or, to enable GNU extensions in addition to C++20 features, add -std=gnu++20.

Important: Because the ISO C++20 standard is very recent, GCC's support is experimental.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...