Строки (C++): различия между версиями
Перейти к навигации
Перейти к поиску
Строка 30: | Строка 30: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | == Задачник == | ||
+ | * [http://ptaskbook.com/ru/tasks/string.php Строки] |
Текущая версия на 13:06, 9 июля 2021
Строки
1 #include <iostream>
2
3 int main() {
4 char ch = '0';
5 std::cout << "Char " << ch << " has code " << (int)ch << std::endl;
6
7 int code = 55;
8 std::cout << "Char " << (char)code << " has code " << code << std::endl;
9
10 std::string str = "Hello";
11 std::cout << "String " << str << " length = " << str.length() << std::endl;
12
13 std::size_t locl = str.find('l', 0);
14 if (locl != std::string::npos) {
15 std::cout << "String " << str << " has l character in position " << locl << std::endl;
16 } else {
17 std::cout << "String doesn't have l char.\n";
18 }
19
20 std::size_t locz = str.find('z', 0);
21 if (locz != std::string::npos) {
22 std::cout << "String " << str << " has z character in position " << locz << std::endl;
23 } else {
24 std::cout << "String doesn't have z char.\n";
25 }
26 }