尝试更改 main 函数内的全局变量值时出现编译错误 C++.


#include<bits/stdc++.h>
using namespace std;

int count;
int main()
{
int k;
cin>>k;
count=k;
cout<<count;
return 0;
}

我正在尝试更改 main 函数中"计数"(全局变量(的值,但在C++中出现reference to 'count' is ambigous错误。但是同样的代码在 C 语言中效果很好。请帮助我。

删除using namespace std;行,将std::添加到cincout,它应该没问题。

您有此编译器错误,因为std::count存在:https://en.cppreference.com/w/cpp/algorithm/count
因此,std::count和变量之间的编译器count不明确,因为您使用using namespace std

最新更新