3

I am using visual studio 2017 and I have run across a problem. When trying to use std::gcd it gives me an error error C2039: 'gcd': is not a member of 'std'

Here's my code:

#include "pch.h"
#include <iostream>
#include <numeric>

int main() {
    std::cout << std::gcd(10, 5);
    return 1;
}
4

2 回答 2

8

std::gcd was added in C++17. To use it in Visual Studio you need to specify the language standard. You can do that two ways, use the /std:c++17 command-line option or in the Project Properties dialog: C/C++ -> Language -> C++ Language Standard.

于 2018-11-11T18:12:48.667 回答
0

I just tested and got the same error with VS2017 15.8.9 after having set the language standard to C++17. When I checked my project settings again, the language setting I made had reverted back to the default. After having set it a second time, it worked.

This seems to happen often when I start a new project and change to C++17 directly.

于 2018-11-11T18:28:52.043 回答