C++练手小程序 用vector使小写文本变为大写


 1 #include <iostream>
2 #include <vector>
3 #include <string>
4 #include <cctype>
5 using namespace std;
6
7 int main()
8 {
9 vector<string> svec;
10 string str;
11
12 // Der Text eingeben.
13 cout << "Eingeben Sie den Text(Ctrl+d):" << endl;
14 while (cin >> str){
15 svec.push_back(str);
16 }
17 cout << endl;
18
19 // Das Programm wird beenden, wenn es keinen Text eingegeben gibt.
20 if (svec.size() == 0){
21 cout << "Sie haben keine Text geschrieben!?" << endl;
22 return -1;
23 }
24
25 // Der eingebende Text anzeigen.
26 cout << "Sie haben folgenden Text geschrieben:" << endl;
27 for (vector<string>::size_type ix = 0; ix != svec.size(); ++ix){
28 cout << svec[ix] << "";
29 }
30 cout << endl;
31
32 // Die haupte Funktion, um das Wort Klein zu Gross zu aendern.
33 for (vector<string>::size_type ix = 0; ix != svec.size(); ++ix){
34 for (string::size_type index = 0; index != svec[ix].size(); ++index){
35 if (islower(svec[ix][index])){
36 svec[ix][index] = toupper(svec[ix][index]);
37 }
38 }
39 }
40
41 // Der wechselde Text anzeigen.
42 cout << endl << "Die Text wird gross geaendert wie folgende: " << endl;
43 for (vector<string>::size_type ix = 0; ix != svec.size(); ++ix){
44 cout << svec[ix] << "";
45 if ((ix + 1) % 7 == 0){
46 cout << endl;
47 }
48 }
49 cout << endl;
50
51 return 0;
52 }


原文链接: https://www.cnblogs.com/FelixLee/archive/2011/04/04/2412603.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++练手小程序 用vector使小写文本变为大写

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/23340

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午1:18
下一篇 2023年2月8日 上午1:19

相关推荐