Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- /////////////////////////////////////////////////////////////////
- int main() //
- {
- POINT cursorPos;
- while(1)
- {
- GetCursorPos(&cursorPos);
- printf("X: %ld, Y: %ld | ", cursorPos.x, cursorPos.y);
- if (GetAsyncKeyState(VK_LBUTTON)) printf("L_Click ");
- if (GetAsyncKeyState(VK_RBUTTON)) printf("R_Click ");
- printf("\n");
- Sleep (1000);
- }
- return 0;
- }
- #include <iostream>
- #include <string>
- #include <locale>
- using namespace std;
- //////////////////////////////////////////////////
- int main()
- {
- setlocale(LC_ALL, "Rus");
- // Конструкторы (C++98)
- string str1; // Пустая строка
- string str2("Hello"); // Из C-строки
- string str3(5, 'a'); // "aaaaa"
- string str4(str2); // Копия str2 ("Hello")
- // Присваивание и модификация
- string str5 = "Initial";
- str5 = "Assigned"; // Присваивание C-строки
- str5.assign( "New value"); // Метод assign
- str5 += " appended"; // Добавление строки
- // Доступ к элементам (C++98 style)
- char ch1 = str2[1]; // 'e' (без проверки границ)
- char ch2 = str2.at(1); // 'e' (с проверкой границ)
- // Итераторы (C++98 style)
- cout << "Итерация по строке: ";
- string::iterator it;
- for(it = str2.begin(); it != str2.end(); ++it)
- {
- cout << *it;
- }
- cout << endl;
- // Поиск и подстроки
- string text = "This is a sample text";
- size_t found = text.find("sample"); // Поиск подстроки
- if(found != string::npos)
- {
- string sub = text.substr(found, 6); // "sample"
- cout << "Найдена подстрока: " << sub << endl;
- }
- // Замена (C++98 style)
- text.replace(10, 6, "example"); // "This is a example text"
- // Сравнение строк
- if(str2 == "Hello")
- {
- cout << "Строки равны" << endl;
- }
- else if(str2.compare("Hello") == 0)
- {
- cout << "Строки равны (через compare)" << endl;
- }
- // Интересный пример 1: Удаление всех пробелов
- string withSpaces = "Text with spaces";
- for(size_t pos = 0; (pos = withSpaces.find(' ', pos)) != string::npos;)
- {
- withSpaces.erase(pos, 1);
- }
- cout << "Без пробелов: " << withSpaces << endl;
- // Интересный пример 2: Преобразование в верхний регистр
- string mixedCase = "Mixed Case String";
- for(string::iterator it = mixedCase.begin(); it != mixedCase.end(); ++it)
- {
- *it = toupper(*it);
- }
- cout << "В верхнем регистре: " << mixedCase << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement