Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cout is ambigous" error when using namespace std #9471

Open
tpkowastaken opened this issue Jun 18, 2022 · 16 comments
Open

"Cout is ambigous" error when using namespace std #9471

tpkowastaken opened this issue Jun 18, 2022 · 16 comments
Labels
bug Language Service verified Bug has been reproduced Works in VS So we'd need to fix it for VS Code to reach parity.
Milestone

Comments

@tpkowastaken
Copy link

Environment

  • OS and version: OS: Windows_NT x64 10.0.19044
  • VS Code: 1.68.1
  • C/C++ extension: version: v1.10.7

Bug Summary and Steps to Reproduce

"Cout is ambigous" error when using namespace std

when programming in c++ while there is a code including this:

#include <iostream>
using namespace std;
int main(){
   cout << "hello world!";
}

then there is a chance that there appears to be "cout is ambigous error" in problems tab even though there is no error to be found whatsoever. It appears for every "cout" in the file. if you write std:: before the cout the error gets removed.

Steps to reproduce:

  1. create a new file called main.cpp and use the c++ language mode
  2. use the msys64 debugger (might not be required but i do make sure to rather include)
  3. write some code with cout in that code with at least 100 lines
    i will include my code on which it does bug out but it wasn't an issue only on this code:
#include <iostream>
#include <fstream>
using namespace std; 
void swap(int *element1, int *element2){
    int tmp = *element1;
    *element1 = *element2;
    *element2 = tmp;
}
void quicksort(int *inputfield, int n){
    cout << "{\ninputfield: ";
    for(int i = 0;i<n;i++){
        cout << inputfield[i] << " ";
    }
    cout << "\n";
    if(n>2){
        //getting the pivot:
        int pivot;
        {
            double pivotaverage = (inputfield[0] + inputfield[n/2] + inputfield[n-1])/3; // average of those pivots
            double a,b,c;
            a = abs(inputfield[0] - pivotaverage);
            b = abs(inputfield[n/2] - pivotaverage);
            c = abs(inputfield[n-1] - pivotaverage);
            if(a<=b && a<=c)pivot = 0; // getting the closest to average
            else if(b<=a && b<=c)pivot = n/2; //getting the closest to average
            else pivot = n-1; // getting the closest to average
            cout << "pivot index: " << pivot << "\n}\n";
            cout << "pivot value: " << inputfield[pivot];
        }
        int i = 0;
        for(int j = 0;j<n;j++){
            if(j == pivot)continue;
            if(i == pivot)i++;
            else if(inputfield[j] > inputfield[pivot])continue;
            else if(inputfield[j] <= inputfield[pivot]){
                //swap inputfield[i] with inputfield[j]
                int tmp = inputfield[i];
                inputfield[i] = inputfield[j];
                inputfield[j] = tmp;
            }
        }
        if(pivot < i){
            //swap pivot with with inputfield[i]
            int tmp = inputfield[i];
            inputfield[i] = inputfield[pivot];
            inputfield[pivot] = tmp;
            quicksort(inputfield, i+1);
            quicksort(inputfield + (i + 1) + 1, (n-((i+1)+1)));//give a pointer to element after the one that is scanned = (i+1) and skip the pointer = +1; then the length is n-that thing
        }
        else if(pivot > i){
            //swap pivot with inputfield[i+1]
            int tmp = inputfield[i+1];
            inputfield[i+1] = inputfield[pivot];
            inputfield[pivot] = tmp;
            quicksort(inputfield, i+1);
            quicksort(inputfield + (i + 1) + 1, (n-((i+1)+1)));//give a pointer to element after the one that is scanned = (i+1) and skip the pointer = +1; then the length is n-that thing
        }
    }
    else if(n == 2 && inputfield[0] > inputfield[1]){ // this is just to faster things up when it gets to the end
        int tmp = inputfield[1]; //Swap
        inputfield[1] = inputfield[0];
        inputfield[0] = tmp;
    }
    //if n = 1 or n = 0 there are no changes needed
}
int main(){
    int *field;
    int n;
    ifstream theFile("input.txt");
    string line;
    if(theFile){
        getline(theFile, line);
        for(int i = 0;line[i] != '\0';i++){
            if(line[i]<58 && line[i]>47){
                n = n*10+(line[i]-48);
            }
        }
        bool negative = false;
        field = new int[n];
        for(int i = 0;i<n;i++){field[i] = 0;}
        int g = 0;
        getline(theFile, line);
        for(int i = 0;line[i] != '\0';i++){
            if(line[i] == '-'){
                negative = true;
                cout << "hey";
            }
            else if(line[i] < 58 && line[i] > 47){
                field[g] = field[g]*10+(line[i]-48);
            }
            else{
                if(negative)field[g] = 0 - field[g];
                negative = false;
                g++;
            }
        }
        if(negative)field[g] = 0 - field[g];
    }
    else return 1;
    cout << n << '\n';
    for(int i = 0;i<n;i++){
        cout << field[i] << " ";
    }
    cout << "\n\n";
    quicksort(field, n);
    cout << "\n";
    for(int i = 0;i<n;i++){
        cout << field[i] << " ";
    }
    delete [] field;
} 
  1. delete the '}' on line 29
  2. wait 5 seconds
  3. write the '}' back on the same line
  4. The problems tab now shows "cout is ambigous error 11 times"
  5. you can compile the code as well to see that it has no errors
  6. It can be run as well just make sure to put input.txt file in the same folder with content such as this:
5
2 4 7 8 9

Note: if you restart vs code or wait long enough (4minutes) and then edit - it mostly disapears.

Other Extensions

I have tested this with only c++ extension v1.10.7 running and C++ extension pack v1.2.0 running.

Additional Information

I have faced this issue on a low-tier laptop which might be a bit slower than usual. Make sure to replicate on lower-end hardware

My specs:
CPU: Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz
Memory: 16GB

A screenshot of this happening:
Captusssre

@sean-mcmanus sean-mcmanus added verified Bug has been reproduced bug Language Service Visual Studio Inherited from Visual Studio labels Jun 20, 2022
@sean-mcmanus sean-mcmanus self-assigned this Jun 20, 2022
@sean-mcmanus sean-mcmanus added this to the On Deck milestone Jun 20, 2022
@sean-mcmanus
Copy link
Contributor

Thanks for reporting this. I've reproed the issue. It doesn't repro with VS. It could be some difference in how we're updating IntelliSense after an edit.

@sean-mcmanus sean-mcmanus added Works in VS So we'd need to fix it for VS Code to reach parity. and removed Visual Studio Inherited from Visual Studio labels May 8, 2023
@sean-mcmanus sean-mcmanus removed their assignment May 8, 2023
@aadia1234
Copy link

aadia1234 commented Jun 23, 2023

Hi, I'm experiencing this exact issue for the first time (June 2023). Here is what I see:
Screenshot 2023-06-23 at 12 11 05 PM

It seems that whenever I'm creating a new statement or modifiyng one of my previous print statements the error occurs. It goes away if I comment then uncomment #include or restart vscode (but reappears soon after)

Specs:
Apple M1 Pro
macOS: 13.3.1 (a) (22E772610a)

VSCode:

Version: 1.79.2
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:58:33.551Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.4.0

@NFGase
Copy link

NFGase commented Jun 23, 2023

same bug, VSCode vision:1.79.2, GCC vision:10.3.0, the code can run well but the terminal remind me that "Cout is ambigous".
image

@ayush110404
Copy link

i am also experiencing same bug issue on the latest release (may 2023) version-1.79.2 and it was even afer the update of latest release.

Screenshot (43)

@CosecSecCot
Copy link

CosecSecCot commented Jun 23, 2023

Yeah, Im also facing the same bug, as of 23 June 2023

image

Why does this appear ? how is cout/cin amigious ??
How to fix this ??

@vasuthakral
Copy link

Same bug appeared

@sean-mcmanus
Copy link
Contributor

FYI, this issue doesn't seem related to the new issue with 1.16.2, because this issue requires very particular edits.

We're tracking the new/regression issue with #11122 .

@cristianVega615
Copy link

I have the same error, apparently the solution is to install the extension pack. Good to me it worked.
This one is without the extension pack
Captura de pantalla (2123)

With extension pack
Captura de pantalla (2122)

@sean-mcmanus
Copy link
Contributor

@tpkowastaken Installing the extension pack is not expected to change the behavior (the bug might repro after making an edit in main). We plan to release a fix in 1.16.3 in the next hour or so.

@CosecSecCot
Copy link

CosecSecCot commented Jun 24, 2023

I reinstalled the C/C++ Extension after v1.16.3 released, the bug is fixed now
You can see, no problems are detected

image

@sean-mcmanus
Copy link
Contributor

Yes, the new 1.16.2 issue is fixed with 1.16.3 (but FYI the original issue is a different bug that still exists, but is harder to repro).

@Kenza1525
Copy link

I have the same error, apparently the solution is to install the extension pack. Good to me it worked. This one is without the extension pack Captura de pantalla (2123)

With extension pack Captura de pantalla (2122)

Thanks it worked when i reloaded the Extension Pack

@jakublATopera
Copy link

I have similar error, not with std::cout and in proprietary code, so for obvious reasons I can't show a screenshot with an error message that a variable defined few lines above in the same anonymous namespace is ambiguous.
Problem appears, disappears and appears again.
Despite reported ambiguity, Ctrl+click works, going to the definition, so wild guess is classifying reparsed type definition as new, while should match with already known to the engine.
C/C++ extension 1.19.9

@sean-mcmanus
Copy link
Contributor

@jakublATopera 1.19.9 has a bug in which missing include errors won't be shown if C_Cpp.errorSquiggles is set to "enabled" (#12134) -- if you change that setting to the default value you may see the cause of the cause is a header that isn't being found. Also, it might be worth seeing if the repro still occurs with 1.18.5.

@DevinF064
Copy link

Hi! I seem to be having a similar issue for the first time as of 05/15/2024. I'm being told that cin is ambiguous, but cout is fine.

C/C++ extension version 1.20.5

image

Included headers are:

#include <iostream>
#include <string>
#include <fstream>
#include <regex>
#include <vector>
#include <map>
#include <cctype>
using namespace std;

@JushBJJ
Copy link

JushBJJ commented Aug 17, 2024

Having this problem as well
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Language Service verified Bug has been reproduced Works in VS So we'd need to fix it for VS Code to reach parity.
Projects
None yet
Development

No branches or pull requests