Строки (C++)
Версия от 07:00, 26 июня 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 }