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

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;
}
    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值