basic_string 缓冲区

来源:百度知道 编辑:UC知道 时间:2024/06/16 02:12:39
我想得到string类对象 的缓冲区,但是我找遍了,无法得到接口.

#include <iostream>
#include <string>
using namespace std;

void main()
{
int i;
string str = "Hello World!";
const char *p = str.c_str();
puts(p);

for (i = 0; i < str.length(); ++i)
{
if ((str[i] >= 'a' && str[i] <= 'z')
|| (str[i] >= 'A' && str[i] <= 'Z'))
str[i] += i;
}

puts(str.c_str());
}

data函数返回的就是

#include <iostream>
#include <string>
using namespace std;

int main()
{
string a = "123";
*(char*)a.data() = 'c';
cout << a;
}