这是一个简单的程序,我的问题是要知道为什么使用命名空间std是必须的?为什么不使用这个程序就不遵守程序?
#include <iostream>
using namespace std;
int main(){
int a , b , c , d;
cout << "Enter First Value" <<endl;
cin >> a;
cout << "Enter Second Value" <<endl;
cin >> b;
cout << "Enter 1 to add values" << endl << "Enter 2 to subtract values" <<endl <<"Enter 3 to multiply values" <<endl ;
cin >> c;
if (c == 1){
d = a + b;
cout << "After Adding your answer is " << d << endl;
}
else if (c == 2){
d = a - b;
cout << "After Subtracting your answer is " << d << endl;
}
else if (c == 3){
d = a * b;
cout << "After Multiplication your answer is " << d << endl;
}
else{
cout << "You Enter Invalid operation to perform";
}
system("pause"); //buitin function to stop the comand screen.
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你不应该(但可以)使用
using namespace std;
Run Code Online (Sandbox Code Playgroud)
您可以std::在该命名空间中的每个对象之前使用,例如:
std::cout << "Enter First Value" << std::endl;
std::cin >> a;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3055 次 |
| 最近记录: |