c++ erstellt einen Thread und führt ihn aus
#include <iostream>
#include <windows.h>
#include <thread>
HANDLE Thread1 = NULL;
int Thread1_bool = 0;
DWORD WINAPI Process_thread(LPVOID lpParameters)
{
int i = 0;
while (Thread1_bool)
{
i++;
if (i == 100)
Thread1_bool = false;
std::cout << "子线程" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
return 0;
}
int main()
{
Thread1 = CreateThread(NULL, 0, Process_thread, NULL, 0, NULL);
Thread1_bool = true;
while (Thread1_bool)
{
std::cout << "主线程" << std::endl;
Sleep(20);
}
std::cout << "结束" << std::endl;
DWORD dwRet = WaitForSingleObject(Thread1, 1000);
CloseHandle(Thread1);
return 1;
}
C++-String-Split
vector<string> split(const string& str, const string& pattern)
{
vector<string> ret;
if (pattern.empty()) return ret;
size_t start = 0, index = str.find_first_of(pattern, 0);
while (index != str.npos)
{
if (start != index)
ret.push_back(str.substr(start, index - start));
start = index + 1;
index = str.find_first_of(pattern, start);
}
if (!str.substr(start).empty())
ret.push_back(str.substr(start));
return ret;
}
std::string str = "abcd_efg";
std::string sp = "_";
vector<string> whd = split(str , sp );