您的位置:首页 > 编程语言 > C语言/C++

C++11标准 类型别名 auto decltype 范围for循环等测试

2017-04-15 11:00 501 查看
C++11标准增加一部分非常好用而又人性化的化的东西,作为C++新手 有必要认真学习一下   对代码质量提高有很大帮助

本博客主要还是供自己学习使用

以下为主要测试代码

#include
#include
using namespace std;
int main()
{
#if 1
cout << "类型别名测试 1.using 2.typedef" << endl;
using double1 = double;
typedef int int1;//+1
double1 d = 3.156;
int1 a = 222;
cout << d << '\t' << a << endl;

int a1 = 1, a2 = 2;
auto sum = a1 + a2;
cout << "auto测试 sum为整型变量" << endl;
cout << "输出4   3" << endl;
cout << sizeof(sum) << " " << sum << endl;
int *p = &a1;
decltype (p) b1;
b1 = &a2;
cout << "decltype测试 b1为指针变量" << endl;
cout << b1 << " " << (*b1) << endl;

cout << "getlineh函数对于string测试" << endl;
string s1;
getline(cin, s1);
cout << "范围for测试" << endl;
for (auto c : s1)
{
c = toupper(c);//字符串大写转换
cout << c;
}
#endif
#if 0
//string内元素也可使用下标运算
string str("hello world");
if (!str.empty())
{
str[0] = toupper(str[0]);
cout << str << endl;
}
#endif

system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++ C++11