Advertisement
dllbridge

Interesting

Mar 29th, 2025 (edited)
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.84 KB | None | 0 0
  1. #include <windows.h>
  2. #include   <stdio.h>
  3.  
  4.  
  5.  
  6. /////////////////////////////////////////////////////////////////
  7. int main()                                                     //
  8. {
  9.    
  10.     POINT cursorPos;
  11.    
  12.     while(1)
  13.     {
  14.         GetCursorPos(&cursorPos);
  15.         printf("X: %ld, Y: %ld | ", cursorPos.x, cursorPos.y);
  16.        
  17.         if (GetAsyncKeyState(VK_LBUTTON)) printf("L_Click ");
  18.         if (GetAsyncKeyState(VK_RBUTTON)) printf("R_Click ");
  19.        
  20.         printf("\n");
  21.         Sleep (1000);              
  22.     }
  23.  
  24. return 0;
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #include  <iostream>
  34. #include    <string>
  35. #include    <locale>
  36. using namespace std;
  37.  
  38. //////////////////////////////////////////////////
  39. int main()
  40. {
  41.     setlocale(LC_ALL, "Rus");
  42.    
  43.                                                  // Конструкторы (C++98)
  44.     string str1;                                    // Пустая строка
  45.     string str2("Hello");                           // Из C-строки
  46.     string str3(5, 'a');                            // "aaaaa"
  47.     string str4(str2);                              // Копия str2 ("Hello")
  48.    
  49.                                                  // Присваивание и модификация
  50.     string str5 =   "Initial";
  51.     str5        =  "Assigned";                      // Присваивание C-строки
  52.     str5.assign( "New value");                      // Метод assign
  53.     str5       += " appended";                      // Добавление строки
  54.    
  55.                                                  // Доступ к элементам (C++98 style)
  56.     char ch1 = str2[1];                             // 'e' (без проверки границ)
  57.     char ch2 = str2.at(1);                          // 'e' (с проверкой границ)
  58.    
  59.                                                  // Итераторы (C++98 style)
  60.     cout << "Итерация по строке: ";
  61.    
  62.     string::iterator it;
  63.    
  64.     for(it = str2.begin(); it != str2.end(); ++it)
  65.     {
  66.         cout << *it;
  67.     }
  68.    
  69.     cout << endl;
  70.    
  71.                                                     // Поиск и подстроки
  72.     string text = "This is a sample text";
  73.     size_t found = text.find("sample");             // Поиск подстроки
  74.     if(found != string::npos)
  75.     {
  76.         string sub = text.substr(found, 6);         // "sample"
  77.         cout << "Найдена подстрока: " << sub << endl;
  78.     }
  79.    
  80.                                                    //    Замена (C++98 style)
  81.     text.replace(10, 6, "example");                // "This is a example text"
  82.    
  83.                                                              //                                      Сравнение строк
  84.     if(str2 == "Hello")
  85.     {
  86.         cout << "Строки равны" << endl;
  87.     }
  88.     else if(str2.compare("Hello") == 0)
  89.     {
  90.         cout << "Строки равны (через compare)" << endl;
  91.     }
  92.    
  93.                                                              //           Интересный пример 1: Удаление всех пробелов
  94.     string withSpaces = "Text with spaces";
  95.     for(size_t pos = 0; (pos = withSpaces.find(' ', pos)) != string::npos;)
  96.     {
  97.         withSpaces.erase(pos, 1);
  98.     }
  99.     cout << "Без пробелов: " << withSpaces << endl;
  100.    
  101.                                                              // Интересный пример 2: Преобразование в верхний регистр
  102.     string mixedCase = "Mixed Case String";
  103.     for(string::iterator it = mixedCase.begin(); it != mixedCase.end(); ++it)
  104.     {
  105.         *it = toupper(*it);
  106.     }
  107.     cout << "В верхнем регистре: " << mixedCase << endl;
  108.    
  109. return 0;
  110. }
  111.  
  112.  
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement