我是靠谱客的博主 冷酷蜻蜓,这篇文章主要介绍33-C++中的字符串类,现在分享给大家,希望可以做个参考。

1、

这里写图片描述

2、

这里写图片描述

复制代码
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream> #include <string> using namespace std; void string_sort(string a[], int len) { for(int i=0; i<len; i++) { for(int j=i; j<len; j++) { if( a[i] > a[j] ) { swap(a[i], a[j]); } } } } string string_add(string a[], int len) { string ret = ""; for(int i=0; i<len; i++) { ret += a[i] + "; "; } return ret; } int main() { string sa[7] = { "Hello World", "D.T.Software", "C#", "Java", "C++", "Python", "TypeScript" }; string_sort(sa, 7); for(int i=0; i<7; i++) { cout << sa[i] << endl; } cout << endl; cout << string_add(sa, 7) << endl; return 0; }

3、

这里写图片描述

4、

这里写图片描述

5、

这里写图片描述

string to int to double and int double to string

stringsteam

复制代码
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
#include <iostream> #include <sstream> #include <string> using namespace std; #define TO_NUMBER(s, n) (istringstream(s) >> n) #define TO_STRING(n) (((ostringstream&)(ostringstream() << n)).str()) int main() { double n = 0; if( TO_NUMBER("234.567", n) ) { cout << n << endl; } string s = TO_STRING(12345); cout << s << endl; return 0; }

6、

这里写图片描述

复制代码
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
#include <iostream> #include <string> using namespace std; string operator >> (const string& s, unsigned int n) { string ret = ""; unsigned int pos = 0; n = n % s.length(); pos = s.length() - n; ret = s.substr(pos); ret += s.substr(0, pos); return ret; } int main() { string s = "abcdefg"; string r = (s >> 3); cout << r << endl; return 0; }

7、

这里写图片描述

最后

以上就是冷酷蜻蜓最近收集整理的关于33-C++中的字符串类的全部内容,更多相关33-C++中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(378)

评论列表共有 0 条评论

立即
投稿
返回
顶部