子串截取:substr(start,size)
String转字符串:c_str()
查找子串:find()
判断是否为空:empty()
替换:replace(start,size,str2)
倒置:reverse(str.begin(),str.end())
长度:length()
插入:insert(start,str,size)
#include<iostream>
#include<stack>
#include<queue>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
using namespace std
;
bool cmp(int a
, int b
) {
if (a
< b
)return false;
else return true;
}
int main() {
int array
[4] = { 1,3,5,2 };
sort(array
, array
+ 4,cmp
);
for (int i
= 0; i
< 4; i
++) {
cout
<< setw(4) << array
[i
];
}
cout
<< endl
;
do {
for (int i
= 0; i
< 4; i
++) {
cout
<< setw(4) << array
[i
];
}
cout
<< endl
;
} while (prev_permutation(array
, array
+ 4));
string str
= "12930";
int strint
= atoi(str
.c_str());
cout
<< strint
+ 1 << endl
;
int numb
= 123456;
string str_1
= to_string(numb
);
string str_2
= "abcdefgh";
string str_3
= str_2
.substr(1, 3);
cout
<< "截取字符串为:" << str_3
<< endl
;
cout
<< "c的位置为" << str_2
.find("c")<<endl
;
cout
<< "cb的位置为" << (str_2
.find("cb")!=str_2
.npos
) << endl
;
str_2
.replace(2, 4, "*");
cout
<< "替换后的字符串为:" << str_2
<< endl
;
reverse(str_2
.begin(),str_2
.end());
cout
<< "倒置后的字符串为" << str_2
<< endl
;
cout
<< fixed
<< setprecision(2) << 3.122 << endl
;
cout
.unsetf(ios
::fixed
);
cout
<< setprecision(2) << 3.1222 << endl
;
queue
<int> que
;
for (int i
= 0; i
< 10; i
++){
que
.push(i
);
}
cout
<< que
.front() << ' ' << que
.back() << endl
;
que
.pop();
cout
<< que
.front()<<' '<<que
.back()<<endl
;
stack
<int> sta
;
for (int i
= 0; i
< 10; i
++) {
sta
.push(i
);
}
cout
<< sta
.top() << endl
;
sta
.pop();
cout
<< sta
.top() << endl
;
map
<string
, int> mp
;
for (int i
= 0; i
< 10; i
++) {
mp
["abc"]++;
}
cout
<< "map:"<<mp
["abc"] << endl
;
system("pause");
return 0;
}
#include<algorithm>
using namespace std
;
int main(){
char ch
[3][10];
for(int i
=0;i
<3;i
++){
cin
>>ch
[i
];
}
for(int i
=0;i
<3;i
++){
cout
<<ch
[i
]<<' ';
}
string str
=ch
[1];
cout
<<str
<<endl
;
system("pause");
return 0;
}
转载请注明原文地址:https://tech.qufami.com/read-7438.html