c++中string类型的常用方法,以及map的使用
#include <iostream>
#include <map>
using namespace std;
string str = "helloworld";
char * buf = (char *)str.data();
int n = 100;
string n_str = std::to_string(n);
string str_str = "100";
int n_int = std::stoi(str_str);
string test_str = "abcdefg";
for(auto n : test_str){
cout << n << endl;
}
string test1_str = "aaabbbcccddd";
string::iterator it = test1_str.remove(test1_str.begin(), test1_str.end(), 'a');
cout << test1_str << endl;
test1_str.erase(it, test1_str.end());
cout << test1_str << endl;
map<int, string> name;
name["1"] = "aaa";
name["2"] = "bbb";
string name_str = name["2"];
for(auto i : name){
cout << i.first << i.second << endl;
}