Advertisement
35657

Untitled

Mar 14th, 2024
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8.  
  9. int main() {
  10.     setlocale(LC_ALL, "ru");
  11.  
  12.     string text = "this is string";
  13.  
  14.     cout << text << endl;
  15.  
  16.     for (int i = 0; i < text.size(); i++) {
  17.         cout << text[i];
  18.     }
  19.     cout << endl;
  20.  
  21.     for (char a : text) {
  22.         cout << a;
  23.     }
  24.     cout << endl;
  25.  
  26.     cout << text.find("is") << endl; // поиск подстроки в строке
  27.     cout << text.find("is", 4) << endl; // поиск подстроки начиная с указанной позиции
  28.     cout << text.rfind("is") << endl; // поиск подстроки с конца строки
  29.     cout << text.find("strong", 0, 3) << endl; // поиск первых трех символов из строки strong в строке text
  30.     cout << text.find_first_of(' ') << endl;
  31.     cout << text.find_last_of(' ') << endl;
  32.     cout << text.find_last_not_of(' ') << endl;
  33.  
  34.     text.erase(3, 5); // удаляем пять символов, начиная с позиции 3
  35.  
  36.     cout << text << endl;
  37.  
  38.     string text2 = "jkbjkbhjb";
  39.  
  40.     text.insert(3, text2); // вставляет строку text2 в указанную позицию
  41.  
  42.     cout << text << endl;
  43.  
  44.     text.push_back('?');
  45.  
  46.     cout << text << endl;
  47.  
  48.     text.pop_back();
  49.  
  50.     cout << text << endl;
  51.  
  52.     cout << text.substr(10) << endl; // возвращает подстроку начиная с указанной позиции
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement