#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int val =0, timer = 0, freq = 50;
while(true) {
Sleep(1000/freq); //win-функция
timer += 1000/freq;
if (timer > 1000) {
timer -= 1000;
cout << val++ << endl;
}
if (GetAsyncKeyState(VK_SPACE)) { //win-функция
cout << "New val: ";
cin >> val;
}
}
system("pause");
return 0;
}
public static void Main()
{
string text = "ничего здесь нет и вообще ничего нигде нет";
Console.WriteLine(text);
int start = 0;
string pattern1 = "ничего";
string pattern2 = "нет";
while(true)
{
int foundS1 = text.IndexOf(pattern1, start);
if (foundS1 == -1)
break;
int foundS2 = text.IndexOf(pattern2, foundS1 + pattern1.Length);
if (foundS2 == -1)
break;
text = text.Remove(foundS1 + pattern1.Length, foundS2 - foundS1-pattern1.Length);
start+= pattern1.Length+pattern2.Length;
}
Console.WriteLine(text);
}
class WinAPI32_Window
{
HWND hWnd = 0; // <--ресурс
public:
WinAPI32_Window()
{
//100 строк для регистрации класса окна и создания окна
hWnd = CreateWindow(/* много параметров */); // <--получаем ресурс
if (!hWnd) throw std::system_error("win creation error"); // кидаем исключение в конструкторе, если окно не создается, то объект не создается тоже
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
}
~WinAPI32_Window()
{
DestroyWindow(hWnd); // <-- освобождение ресурса
}
}
//ну а дальше в программе:
try {
auto win = new WinAPI32_Window; //создаем объект = инициализируем и получаем внутри hWnd
} catch //...
//работаем
delete win; //освобождаем ресурс путем удаления объекта
#include <string>
#include <iostream>
#include <stdexcept>
int r1_input(const std::string& str)
{
using namespace std;
string varname = "r1_input=";
auto start = str.find(varname);
if (start == string::npos)
throw invalid_argument(varname+ " not found");
start += varname.size();
auto end = str.find("?", start);
size_t len = (end == string::npos) ? string::npos : end-start;
return stoi(str.substr(start, len));
}
int main()
{
std::string input = "GET /set?r1_input=123?&nocache=885898.3828703746 HTTP/1.1";
std::cout << r1_input(input) << std::endl;
system("pause");
return 0;
}
//for (const std::pair<uint32_t, Parameter>& p : m.parameters)
foreach ($m->parameters as $k => $v) {
//QString start = QString::fromUtf8(p.second.start.c_str());
$start = $v->start;
// m_parameters[p.first] = value;
$this->m_parameters[$k] = $value;
// m_parametersVisibility[p.first] = true;
$this->m_parametersVisibility[$k] = True;
}
struct database{
std::string myName; //char myName[124];
std::string city; //char city[124];
int age;
};
sort(infa.begin(), infa.end(), [](const infa& a, const infa& b) {
return strcmp(a.myName, b.myName) < 0;
});
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
int main()
{
std::ifstream file("test.cfg");
std::vector<std::string> buffer;
std::string line;
while (std::getline(file,line)) {
buffer.push_back(line);
}
std::cout << buffer[rand()%buffer.size()] << std::endl;
system("pause");
return 0;
}