這是一個簡單的程序,我的問題是要知道爲什麼強制使用名稱空間std?爲什麼不使用這個程序不遵守?爲什麼在C++語言中使用命名空間標準是必須的?
#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;
}
它實際上是強制性的對面。爲了簡潔起見,它主要用於C++書籍。但在現實世界中,拉動整個'命名空間std'會導致嚴重的頭痛。 – 101010
*爲什麼使用namespace std強制使用*它不是。 – Borgleader
不好的做法,使用它:http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice –