2021-07-25

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;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值