#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::
添加到cin
并cout
,它应该没问题。
您有此编译器错误,因为std::count
存在:https://en.cppreference.com/w/cpp/algorithm/count
因此,std::count
和变量之间的编译器count
不明确,因为您使用using namespace std
。