幕布斯7119047
2021-12-08 15:11:45
#include <iostream>namespace std;int main(){int a=0;std::cout<<a<<std::endl;std::cin.get();return 0;}為什么會出錯error C2059: syntax error : ';'為什么會報這個錯~~還有要我加using namespace std;的就算了#include <iostream>int main(){int a=0;std::cout<<a<<std::endl;std::cin.get();return 0;}為什么這樣又沒錯? 打個比方吧比如有兩個AB函數他們在不同的庫~~但是我同樣需要這兩個函數所以我要兩個空間比如std::AB()與boost::AB() 難道就沒有一個讓我滿意的答案么
3 回答

守著星空守著你
TA貢獻1799條經驗 獲得超8個贊
你根本沒有理解iostream的幾種書寫方式,不要怪程序,很多是你自己沒掌握
正確的寫法是一下的幾種:
1.#include <iostream.h>
2 #include <iostream>
using namespace std;
3.#include <iostream>
std::cin>>;
std::cout<<a<<std::endl;
當然有的編譯器有可能只支持其中的部分書寫方式
1.是老版本的書寫方式
2.是標準的書寫方式

至尊寶的傳說
TA貢獻1789條經驗 獲得超10個贊
首先,命名空間這個東西,用法是using namespace std;,你沒寫USING,再其次,用了命名空間之后,cin和cout前面就不要加STD::
一下兩種都是可以的
#include <iostream>
using namespace std;
int main()
{
int a=0;
cout<<a<<endl;
cin.get();
return 0;
}
#include <iostream>
int main()
{
int a=0;
std::cout<<a<<std::endl;
std::cin.get();
return 0;
}
添加回答
舉報
0/150
提交
取消