c++ - 尝试在 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 中运行良好。请帮助我。
解决方案
删除该using namespace std;
行,添加std::
到cin
andcout
应该没问题。
你有这个编译器错误,因为std::count
存在:https
:
//en.cppreference.com/w/cpp/algorithm/count 所以它std::count
和你的变量之间的编译器是模棱两可的,count
因为你使用using namespace std
.
推荐阅读
- php - 无法使用 sqlserver 连接到数据库?
- flutter - 如何在 Flutter 的画布上的路径内绘制图案?
- ansible - Ansible - 环境变量剧本
- python - Flask - 更改现有数据库中的列类型
- swift - 复选框不能在 swift 中单独工作。我怎样才能让它分开?
- azure - 创建 Azure 管道时出现 ResourcePurchaseValidationFailed 错误
- c - C++ 表达式必须有一个常量值。(我在 Visual Studio 2019 中用 C 语言编写代码)
- javascript - 数组中每个项目的打印选项
- android - 当应用程序首先从 Play 商店应用程序启动然后从主屏幕启动时,OnCreate 会被多次调用
- r - R:为什么在阅读我的 .txt 文件后,我的数据框中会出现一个标题为“X.1”的额外列?