#include <ppltasks.h> #include <string> #include <windows.h> using namespace concurrency; using namespace std; int wmain() { task<int> t([]() { int rnd; rnd = GetTickCount() % 500; for (int i = 0; i<rnd; i++) rand(); return rand() % 100; }); t.wait(); wchar_t str[40]; swprintf(str, 40, L"0~99の乱数: %d\n\n", t.get()); OutputDebugString(str); } |
#include <ppltasks.h> #include <string> #include <windows.h> using namespace concurrency; using namespace std; task<int> int_rand() { int rnd = GetTickCount() % 500; return create_task([rnd] { for (int i=0; i<rnd; i++) rand(); return rand() % 100; }); } int wmain() { auto t = int_rand(); wchar_t str[40]; swprintf(str, 40, L"0~99の乱数: %d\n\n", t.get()); OutputDebugString(str); } |
#include <ppltasks.h> #include <string> #include <windows.h> using namespace concurrency; using namespace std; task<wstring> return_string() { auto s = make_shared<wstring>(L"Return_String"); return create_task([s] { wstring str; str = L"Value: " + *s + L"\n"; return str; }); } int wmain() { wstring str; auto t = return_string(); str = L"Final value: " + t.get() + L"\n"; OutputDebugString(str.data()); } |