时间:2025-11-09 18:00
人气:
作者:admin
本文记录了没有main的例外程序以及命名空间的几种使用方法。
main() 的例外程序main();main();_tmain()。这种情况下,有一个隐藏的 main(),它调用 _tmain()。让标准命名空间(std)的元素在程序中可用的几种不同选择如下:
将以下内容放在文件中的所有函数定义上方,这样std命名空间中的所有内容就对该文件中的每个函数都可用了:
using namespace std;
将以下内容放在特定的函数定义中,使std命名空间的所有内容可用于该特定函数:
using namespace std;
在特定的函数定义中放置如下所示的using声明,使某个特定元素(例如cout)可用于该函数 (或者放在文件中的所有函数定义上方,特定元素(例如cout)就对该文件中的每个函数都可用):
using std::cout;
完全省略using指令和声明,并且在使用std命名空间中的元素时,始终使用std::前缀:
std::cout << "I’m using cout and endl from the std namespace" << std::endl;