首页 > 解决方案 > 尝试在 C++ 中更改主函数内的全局变量值时出现编译错误

问题描述

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


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

我正在尝试更改主函数中“计数”(全局变量)的值,但reference to 'count' is ambigous在 C++ 中出现错误。但是相同类型的代码在 C 中运行良好。请帮助我。

标签: c++compiler-errors

解决方案


删除该using namespace std;行,添加std::cinandcout应该没问题。

你有这个编译器错误,因为std::count存在:https
: //en.cppreference.com/w/cpp/algorithm/count 所以它std::count和你的变量之间的编译器是模棱两可的,count因为你使用using namespace std.


推荐阅读