尝试更改 main 函数内的全局变量值时出现编译错误 C++.
Getting Compilation error while trying to change global variable value inside the main function in 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::
添加到cin
并cout
,它应该没问题。
您有此编译器错误,因为std::count
存在:https://en.cppreference.com/w/cpp/algorithm/count
因此,std::count
和变量之间的编译器count
不明确,因为您使用using namespace std
。
相关文章:
- 使用变量值作为 PlaySound 中的路径
- 通过指针偏移量访问结构变量值
- 变量值在 C++ 中的 glutIdleFunc() 中未递增
- 更新 #ifdef 中的现有变量值?
- 尝试更改 main 函数内的全局变量值时出现编译错误 C++.
- 通过 Rcpp 和 bit64 R 包将最大的int64_t变量值从 C++ 传递到 R
- 如何使用 IRBuilder 更新 LLVM IR 中的全局变量值?
- 更改已在运行的程序的变量值
- 在 Xcode 中使用后对外部变量值进行初始化
- C++整数变量值
- 变量值,在三元运算符之后
- 如何获得对不同类的引用,以便从所述类内部获得变量值
- Java应用程序的JNI-c++变量值
- 如何固定从传感器获得的变量值
- 离开方法时重置变量值
- 打印具有通用特定变量值的类对象
- 在宏函数C++中设置宏变量值
- 为什么每次迭代都会获得相同的变量值? C++
- 如何根据基类对象中的变量值分配派生类中的变量?
- 如何将全局字符变量值分配给数组?