forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.17.cpp
29 lines (24 loc) · 775 Bytes
/
6.17.cpp
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
#include <string>
#include <iostream>
bool hasCapital(const std::string &s) { // Only ASCII
for (auto &c : s) // `c` would be `const char &` since `s` is `const`
if (c >= 'A' && c <= 'Z')
return true;
return false;
}
void toLowerStr(std::string &s) { // Only ASCII
for (auto &c : s)
if (c >= 'A' && c <= 'Z')
c -= 'A' - 'a';
}
// The parameters have different type, because in `hasCapital`, we don't need
// to change the string, but in `toLowerStr`, we need to change the string.
int main() {
std::string str("Hello World!");
std::cout << hasCapital("Abc") << " " << hasCapital("abc") << " "
<< hasCapital(str) << std::endl;
std::cout << str << std::endl;
toLowerStr(str);
std::cout << str << std::endl;
return 0;
}