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++11新特性:类型别名,auto类型,decltype类型
- C++11特性--auto,decltype,返回类型后置,using=,nullptr
- 类型别名,auto类型说明符,decltype类型指示符
- C++11常用特性学习-易学易用新特性(>>/auto/decltype/范围的for)
- C++primer---constexpr、类型别名、auto、decltype
- 2.5类型别名,auto, decltype
- c++11之auto自动类型推断和decltype类型获取
- c++11的一些特性auto和范围for循环
- C++11:"auto"和"decltype"类型说明符的思考
- C++11特性:auto关键字与基于范围的for循环
- c++11 学习及测试(auto,decltype,range for...)
- C++11系列-改进的类型推导:auto、decltype和新的函数语法
- C++学习笔记-const对象,类型别名,auto和decltype
- C++11系列-改进的类型推导:auto、decltype和新的函数语法
- C++11系列-改进的类型推导:auto、decltype和新的函数语法
- c++11——auto,decltype类型推导
- C++11初探:类型推导,auto和decltype
- 杂货边角(12):C++11动态性来源之类型推断 && auto\decltype\追踪返回类型
- c++11的一些特性auto和范围for循环
- C++11系列-改进的类型推导:auto、decltype和新的函数语法