C++ 中 能用string 的就不要用C语言中的字串.....

本文摘自《C++ Primer》第四版,探讨了C风格字符串的安全隐患,并推荐使用std::string来提高代码安全性。作者建议:首先考虑使用std::string;操作C风格字符串时,先复制到std::string中;需要C风格字符串时,利用std::string::c_str()获取。

In C++ Primer (version 4), the author discussed the security issues about C style string.Then std::string is put forward to display her advantage and use.

 

Some advices made by me to give you :

1.Use string first.

2.When you operate  a C Style string ,you can create a new string object to copy the C Style String.Then operate the generated string ..

3.When you use string, you  want to get a C Style string ,you can use string::c_str() to get a C style string pointer.Attention about this is only a pointer....

 

 

I commend every one to use string  except you must use C style string!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值