C++
备忘录
C++备忘录
github
二维数组
#include
using namespace std;
int main() {
// 已知大小
int arr_1[2][3] = { {1, 2, 3}, {4, 5, 6} };
// 未知大小
// 创建
int m = 2, n = 3;
int** arr_2 = new int*[m];
for (int i = 0; i < m; i++) {
arr_2[i] = new int[n];
}
// 删除
for (int i = 0; i < m; i++) {
delete[] arr_2[i];
}
delete[] arr_2;
return 1;
}
STL container
#include
#include
#include
#include
#include
STL algorithm
#include
#include
#include
#include
#include
string
#include
#include
#include
#include
using namespace std;
int main() {
string s = "abcde";
string s_s = s.substr(1, 3);
cout << s_s << endl;
int idx = s.find("da");
cout << idx << endl;
string::size_type idx_1 = s.find('q');
cout << idx << endl;
cout << (idx==string::npos) << endl;
cout << (idx==-1) << endl;
s.append("w");
s.insert(0, "2");
cout << s.front() << s.back() << stoi(s) << s.compare("21") << s.length() << s.size() << endl;
string s_2 = "qwert";
s += s_2;
cout << s;
s.erase(0, 3);
cout << endl << s << endl;
return -1;
}
评论列表(0条)