2014年3月31日

每天学一点c++:##

摘要: ##连接前后的内容,使之成为一个整体示例:#include #include using namespace std;#define concatenate(x) x ## yint main(){ string xy ="Hello,World!"; cout << concatenate(x,y) <<endl; return 0;}cout << concatenate(x,y) <<endl;等同于cout << xy <<endl; 阅读全文

posted @ 2014-03-31 16:49 敖天 阅读(177) 评论(0) 推荐(0)

每天学一点c++:#

摘要: #是预处理宏#define使用的,#使#后的第一个参数返回一个带双引号的字符串示例:#include using namespace std;#define toString(s) # sint main(){ cout << toString(Hello World!) <<endl; return 0;}cout << toString(Hello World!) <<endl;可以看做是cout << "Hello World!" <<endl;输出Hello World! 阅读全文

posted @ 2014-03-31 16:31 敖天 阅读(219) 评论(0) 推荐(0)

每天学一点c++:c++命名空间

摘要: 在c语言中,当程序达到一定的规模之后,会遇到的一个问题是我们“用完”了函数名和标识符。当然,并非真的用完了,只是简单的想出一个有意义的新名称不太容易了。在C++中,有预防这种冲突的机制:namespace关键字。只要标识符定义在不同的空间中,就不会产生冲突。如果要使用某个命名空间中的声明或定义,就用关键字using,比如using namespace std;定义一个命名空间:namespace MyNamespace{ //Declarations声明序列}使用命名空间:不使用using指令,这个命名空间的所有名字都需要被完全限定:#includeint main(){ st... 阅读全文

posted @ 2014-03-31 09:53 敖天 阅读(223) 评论(0) 推荐(0)

导航