函数 | 头文件 | 用法 | 作用 |
---|
sqrt | cmath | sqrt(double) | 开平方 |
reverse | algorithm | reverse(v.begin(),v.end()) | 反转字符串 |
pow | cmath | pow(double,double) | 幂 |
ostringstream stream | sstream | | int->string&string->int |
isalpha | iostream | isalpha(char) | 是否是字母 |
ostringstream stream;
stream<<n;
return stream.str();
ostringstream os;
int i = 12;
os << i;
cout << os.str() << endl;
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main(void){
string str1="We can insert a string";
string str2="a str into ";
cout <<str1.insert(14,str2)<<endl;
cout <<str1.insert(14,str2,2,9)<<endl;
cout <<str1.insert(14,"test hello",5)<<endl;
cout <<str1.insert(14,6,'*')<<endl;
cout <<str1.replace(3,3,"may")<<endl;
cout <<str1.replace(3,3,"can could",4,5)<<endl;
cout <<str1.replace(3,5,"can could",3)<<endl;
cout <<str1.replace(3,3,5,'*')<<endl;
string word="We";
size_t index=str1.find(word);
if(index!=string::npos)
cout <<str1.erase(index,word.length())<<endl;
return 0;
}
![这里写图片描述](https://img-blog.csdn.net/20180311144657582?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTXFfR28=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)