STL:大小写字母转换、字符转数字、char*转string(未完待续)

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
int main()
{
     // 字符转大小写
     cout << (char)toupper( 'a' ) << endl;
     cout << (char)toupper( 'A' ) << endl;
     cout << (char)tolower( 'a' ) << endl;
     cout << (char)tolower( 'A' ) << endl;
     puts( "×××××××××××××××××××完××××美××××分××××割××××线×××××××××××××××××××" );
 
     //char 转 int,long int,long long int,double
 
     //方法一:atoi atol atoll atof
     char s1[]= "12345654" ;
     char s2[]= "123.23" ;
     int n1 = atoi(s1);
     long int n2 = atol(s1);
     long long int n3 = atoll(s1);
     double n4 = atof(s2);
     cout << n1 <<  ' '  << n2 <<  ' '  << n3 <<  ' '  << n4 << endl;
 
     //方法二:sscanf
     int a1;
     sscanf(s1, "%d" ,&a1);
     cout << a1 << endl;
 
     double a2;
     sscanf(s2, "%lf" ,&a2);
     cout << a2 << endl;
 
     char s3[]= "AF" ;
     int a3;
     sscanf(s3, "%X" ,&a3);  //16进制转换成10进制
     cout << a3 << endl;
 
     puts( "×××××××××××××××××××完××××美××××分××××割××××线×××××××××××××××××××" );
 
 
     //cstring 与 string 的转换
     string s4 =  "This is a test" ;
     char s5[20];
     s5.format( "%s" , s4.c_str());
     cout << s5 << endl;
}

转载于:https://www.cnblogs.com/bestwzh/p/6401779.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值