Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改ex3.22的程序 #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions ch03/exercise3_22.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
#include <iostream>
#修改之前那个输出text第一段的程序,首先把text的第一段全都改成大写形式,然后再输出它。

#include <vector>
#include <cctype>
#include <iterator>
#include <string>
#include <iostream>

using namespace std;

int main()
{
vector<string> text;
text.push_back("aaaaaaaaaa aaaaaaaaa aaaaaa");
text.push_back("");
text.push_back("bbbbbbbbbbbbbb bbbbbbbbbbb bbbbbbbbbbbbb");

vector<string>text;
text.push_back("aaa bbb ccc ddd eee fff");
for (auto it = text.begin(); it != text.end() && !it->empty(); ++it)
{
for (auto &c : *it)
{
if (isalpha(c)) c = toupper(c);
}
for (auto it2 = it->begin(); !isspace(*it2); ++it2)
if (isalpha(*it2))
*it2 = toupper(*it2);
}

for (auto it : text)
{
cout << it << endl;
}
return 0;
}
}