c++ stirng的使用

来源:互联网 发布:2017机顶盒破解软件 编辑:程序博客网 时间:2024/06/02 23:30
#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;}

0 0
原创粉丝点击