C++快速回忆
String
(1)find()函数:
string s="sd12345fghjkjhgfdsdfghjoiuytrertyui";
string subs="12345";
int index=s.find(subs,0);
//输出“2”
(2)c_str()
c_str()是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址。换种说法,c_str()函数返回一个指向正规C字符串的指针常量,内容与本string串相同。这是为了与C语言兼容,在C语言中没有string类型,故必须通过string类对象的成员函数c_str()把string对象转换成C中的字符串样式。
char *cstr, *p;
string str("Please split this phrase into tokens");
cstr = new char[str.size() + 1];
strcpy(cstr, str.c_str());//在C++中使用时需要包含头文件<cstring>
(3)atoi()、itoa()
atoi(): 是C语言中的字符串转换成整型数的一个函数。函数原型如下:
int atoi(const char *nptr);
string intdata="123";
int data;
data=atoi(intdata.c_str());//使用时必须要采用c_str()将string类对象转换一下
itoa(): 函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用的基数。在上例中,转换基数为10。10:十进制;2:二进制
sprintf也可以用来将字符串转换为整数
char x[10];
int data=123;
sprintf(x, "%d", data);
3、to_string()
整数转字符串
int y=89;
string strv=to_string(y);
Vector
https://www.cnblogs.com/yskn/p/9053161.html
Map
https://www.w3cschool.cn/cpp/cpp-fu8l2ppt.html
https://www.cnblogs.com/magisk/p/9193351.html
Stack/deque
https://www.cnblogs.com/magisk/p/9193351.html
cout
输出保留指定小数位个数
double x = 3344.12467;
cout<<fixed<<setprecision(3)<<x<<endl;