altrko's blog

By altrko, history, 2 days ago, In English

I am using C++ and as we all know we have this function __gcd(a,b). but for some reason using this was giving me error. So I thought it was my c++ version and changed it in Vscode. So now it shows in Vscode that i have that new version but when i run the program in terminal (there is a specific program which tells the version of c++ you are using in Vscode, i'll put link below) it still shows me old version that I was using. Therefore i still have same error. Pls someone help.

heres link: https://coderslegacy.com/c/check-cpp-compiler-version/

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
42 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

Can you send your code here?

  • »
    »
    39 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    there is nothing to send i just say cout <<__gcd(3,5); and its giving me error

    • »
      »
      »
      39 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      all the code and all the included libraries.

      • »
        »
        »
        »
        39 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        // this is code
        
        #include <bits/stdc++.h>
        using namespace std;
        
        #define ll long long
        #define N (int) 2e5
        #define mod (ll) 1e9+7
        
        ll aa[N],ans;
        
        int main ()
        {
            
            ios::sync_with_stdio(false);
        	cin.tie(NULL);cout.tie(NULL);
        
        	cout <<__gcd(3,4)<<endl;
        
        
        }
        
        
»
42 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Are you using #include cmath?

»
41 hour(s) ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Which compiler do you use? For example MSVC doesn't have it

Anyways you can just use std::gcd

  • »
    »
    39 hours ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    i don't know i haven't changed anything since downloading c++ on vscode. it still give me error when i use std::gcd(a,b) like howw

    • »
      »
      »
      36 hours ago, # ^ |
      Rev. 2   Vote: I like it +5 Vote: I do not like it

      Please don't “download c++ on vscode” unless you know clearly what programs are installed. Just get to know more about different compilers and choose one to install on your machine. Sometimes a shortcut may bring you more pain afterward.

»
41 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

__gcd(a,b) is a compiler-specific extension and may not be available in all environments.

Use gcd(a,b) instead, from #include <numeric>.

std::gcd is part of the C++17 standard, making it portable and reliable across different compilers.

  • »
    »
    38 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    it sill gives me same error

    • »
      »
      »
      37 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Could you please add the error message here.

      • »
        »
        »
        »
        36 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        ./AA.cpp:23:7: error: use of undeclared identifier '__gcd' d = __gcd(a,b);

      • »
        »
        »
        »
        31 hour(s) ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Error Messege while you are using gcd(3,4) please

        • »
          »
          »
          »
          »
          4 hours ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          it doesn't show me anything else just that on terminal

»
36 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

contact saini_84 for vs code issues , contact number — 9381796116