Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "ru");
- string text = "this is string";
- cout << text << endl;
- for (int i = 0; i < text.size(); i++) {
- cout << text[i];
- }
- cout << endl;
- for (char a : text) {
- cout << a;
- }
- cout << endl;
- cout << text.find("is") << endl; // поиск подстроки в строке
- cout << text.find("is", 4) << endl; // поиск подстроки начиная с указанной позиции
- cout << text.rfind("is") << endl; // поиск подстроки с конца строки
- cout << text.find("strong", 0, 3) << endl; // поиск первых трех символов из строки strong в строке text
- cout << text.find_first_of(' ') << endl;
- cout << text.find_last_of(' ') << endl;
- cout << text.find_last_not_of(' ') << endl;
- text.erase(3, 5); // удаляем пять символов, начиная с позиции 3
- cout << text << endl;
- string text2 = "jkbjkbhjb";
- text.insert(3, text2); // вставляет строку text2 в указанную позицию
- cout << text << endl;
- text.push_back('?');
- cout << text << endl;
- text.pop_back();
- cout << text << endl;
- cout << text.substr(10) << endl; // возвращает подстроку начиная с указанной позиции
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement