gpt4 book ai didi

c++ - 为什么在c++语言中必须使用using namespace std?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:05:31 24 4
gpt4 key购买 nike

<分区>

这是一个简单的程序,我的问题是知道为什么必须使用 using namespace 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;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com