读书人

C++中的函数声明小疑点

发布时间: 2012-03-27 13:44:24 作者: rapoo

C++中的函数声明小问题
在C++中,当我们声明要调用的函数,是在using namespace std;后面还是在main函数中声明?两者又有什么不同?

[解决办法]

探讨
在C++中,当我们声明要调用的函数,是在using namespace std;后面还是在main函数中声明?两者又有什么不同?

[解决办法]
C/C++ code
#include <iostream>using namespace std;void fun();int main(){    cout<<"main"<<endl;    fun();    return 0;}void fun(){    cout<<"fun"<<endl;}//这种方式的输出为 main fun#include <iostream>void fun();int main(){    using namespace std;    cout<<"main"<<endl;    fun();    return 0;}void fun(){    cout<<"fun"<<endl;}//这种方式编译器会报错误说,fun函数里的cout和endl没有定义 

读书人网 >C++

热点推荐