我是靠谱客的博主 标致冰淇淋,这篇文章主要介绍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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream> #include<fstream> #include <algorithm> #include<string> using namespace std; class Words { public: // 获取输入字符串到文件中 void ppsssWords() { ofstream outfile("字符处理.txt"); gets_s(m_strWords); outfile << m_strWords; outfile.close(); } // 获取文件中的单词,输出到数组str中,并进行排序 void paxu() { ifstream infile("字符处理.txt"); string str[10], tame; int count_str = 0; infile >> str[count_str]; while (!infile.eof()) { count_str++; infile >> str[count_str]; } for (int i = 0; i <= count_str; i++) { cout << str[i] << " "; } cout << endl; for (int j = 0; j <= count_str - 1; j++) { for (int i = 0; i <= count_str - j - 1; i++) { if (str[i][0] > str[i + 1][0]) { tame = str[i]; str[i] = str[i + 1]; str[i + 1] = tame;//交换相邻的 } } } for (int i = 0; i <= count_str; i++) { cout << str[i] << " "; } cout << endl; } private: char m_strWords[100]; int t; }; int main() { Words word; word.ppsssWords(); word.paxu(); }

最后

以上就是标致冰淇淋最近收集整理的关于string数组按照字母排序的全部内容,更多相关string数组按照字母排序内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部