my g++ version is 9.3.0 but std::lcm() std::gcd() is not working. An error message is showing that "'lcm' was not declared in this scope" or "'gcd' was not declared in this scope". what should I do?
UPD: problem solved...keeping this post for those people who are encountering similar problem.
There're no such functions called gcd() or lcm(). (only before C++17,thanks MohamedMagdy for correcting my mistake)
However, there're something called __gcd()
If you want the GCD of a and b, you can write the following code:
And for LCM:
There's std::gcd since C++ 17 https://en.cppreference.com/w/cpp/numeric/gcd
(sorry, I'm outdated)
Try to compile with -std=c++17 option.
i have latest c++17 minGW compiler(before c++20) in my machine. But it still showing this error. How should i use this in my local compiler?
I can use all the functionality of c++17 except using std::gcd() and std::lcm()
I compile with
-std=c++2a
and both gcd and lcm work. You can get C++20 (beta?) compiler from here : http://mingw.org/Can you please tell me what is the difference between -std=c++2a and -std=c++17? And how can I download c++20 from http://mingw.org/ this website? TIA :D
I use Windows. I installed like this:
On left side of http://mingw.org/wiki/Install_MinGW, there is link to download installer, under popular content.
http://mingw.org/download/installer
https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/
For differences between C++20 and C++17, just google it, or this might help: https://en.cppreference.com/w/cpp/20#C.2B.2B20_core_language_features
I updated my compiler a few weeks ago, GNU has not released one which has all the features of C++20, but some are there.
For more info: https://gcc.gnu.org/projects/cxx-status.html
C++2a Support in GCC GCC has experimental support for the next revision of the C++ standard, which is expected to be published in 2020.
Quoted from there: