#include <iostream>
#include <string>
using namespace std;
int main()
{
char buf[100] = {0};
const char* attr = "{\"loop_back\":\"1\",\"aneg\":\"0\"}";
strncpy(buf, attr, strlen(attr));
string attr_buf(buf);
cout << attr_buf << endl;
cout << attr_buf.length() << endl;
string::size_type char_loc;
while (string::npos!=(char_loc=attr_buf.find('\"')))
{
attr_buf.erase(char_loc,1);
cout << "char_loc:" <<char_loc<<endl;
}
cout << attr_buf << endl;
cout << attr_buf.length() << endl;
while (string::npos!=(char_loc=attr_buf.find('{')))
{
attr_buf.erase(char_loc,1);
cout << "char_loc:" <<char_loc<<endl;
}
cout << attr_buf << endl;
cout << attr_buf.length() << endl;
while (string::npos!=(char_loc=attr_buf.find('}')))
{
attr_buf.erase(char_loc,1);
cout << "char_loc:" <<char_loc<<endl;
}
cout << attr_buf << endl;
cout << attr_buf.length() << endl;
string tmp("protocl_name,");
attr_buf.insert(0,tmp);
cout << attr_buf << endl;
cout << attr_buf.length() << endl;
return 0;
}
c++ stirng的使用
最新推荐文章于 2024-08-22 10:51:34 发布