Files
learning/cpp/Типы данных/строки.cpp
2022-05-06 00:49:26 +03:00

35 lines
1.2 KiB
C++
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
using namespace std;
int main() {
/* Строки
Существует 2 типа: string (стиль c++) и массив char (стиль c)
Синтаксис:
string имя = "строка";
char имя = {"строка"};
Методы string:
.append(string) - добавить строку в конец
.push_back(char) - добавить символ в конец
.insert(i, string) - добавить строку на индекс i
.erase(i, j) - удалить элементы стоящие между i и j
.find(item) - возвращает индекс элемента
.length() - возвращает длину
.size() - тоже возвращает длину
*/
string myStr = "string";
char myChArr[] = {"string"};
cout << myStr << endl;
cout << "Размер: " << myStr.size() << "; Длина: " << myStr.length() << endl;
cout << "Позиция подстроки 'tr': " << myStr.find("tr") << endl;
cout << "Позиция подстроки 'if': " << myStr.find("if") << endl; // Выводит неприменимое число
cout << "Все символы строки 'string':"<< endl;
for (int i = 0; i < myStr.length(); i++) {
cout << myStr[i] << endl;
}
return 0;
}