C++ string类的c_str()方法小结

最近研究了一下基于c++的大数乘法算法, 碰到了string类对象与c风格字符串转换问题,有一个问题令我印象深刻,现在没有找到具体原因,记录下来。代码环境是Linux ubuntu,编译器是g++

觉得写得比较好的博客罗列如下:

【转】https://www.cnblogs.com/lifexy/p/8642163.html

1.c_str()

c_str()方法返回一个const char* 类型的指针变量, 该指针变量指向一个字符数组, 字符数组的元素个数是string::length() + 1,最后一个元素为 '\0'

以下为官方说法:

const charT* c_str() const;
Returns: A pointer to the initial element of an array of length size() + 1 whose first size() elements equal the corresponding elements of the string controlled by *this and whose last element is a null character specified by charT().
Requires: The program shall not alter any of the values stored in the array. Nor shall the program treat the returned value as a valid pointer value after any subsequent call to a non-const member function of the class basic_string that designates 
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值