-2

I'm using Visual Studio 2017. I have a problem in writing GCD code and I can't find out any mistake. The errors are "identifier not found", and "gcd is unidentified". Here is my code:

#include "stdafx.h"
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    cout << __gcd(12, 40); 
}
  • 1
    Well, I would begin by including `numeric` just to make sure it is included... http://en.cppreference.com/w/cpp/header/numeric (`gcd` is in the `numeric` standard header) then getting rid of the underscores might help... – pepperjack Jan 03 '18 at 02:55
  • 3
    What led you to believe that Visual C++ has a function named `__gcd`? – Retired Ninja Jan 03 '18 at 02:57
  • In situations like this, you can trust that the compiler is smarter than you. –  Jan 03 '18 at 03:03
  • What is `__gcd` and what made you believe that such function even exists? – AnT Jan 03 '18 at 03:05

1 Answers1

2

It's a hidden gem in libstdc++ but not in MSVC. Reference

I am able to call this function on an Ubuntu 16.04 install as well as Windows Subsystem for Linux, but not Windows.

Note as well, there's a std::gcd() function available in C++17, in header numeric. See the same reference above.

iBug
  • 32,728
  • 7
  • 79
  • 117