我正在尝试用C++编写一个非常简单的程序,它找到两个数字的模数,如下所示:
#include <iostream>
using namespace std;
int n;
int d;
int modulus;
int main()
{
cout<<"***Welcome to the MODULUS calculator***";
cout<<"Enter the numerator, then press ENTER: ";
cin>>n;
cout<<"Enter the denominator, then press ENTER: ";
cin>>d;
modulus=n%d;
cout<<"The modulus is ---> "<<modulus;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译它时,我得到以下内容:

怎么解决这个问题?
谢谢.
您收到错误,因为全局变量的名称modulus与之冲突std::modulus.要解决此问题,您可以:
modulus一个局部变量modulus变量using namespace std并从std单独导入您需要的名称或使用它们进行限定std::