#pragma comment(lib, "rpcrt4.lib") #include <iostream> #include <time.h> #include <windows.h> #include <sstream> #include <fstream> using namespace std; string getTimeStringDemo1(); string getUuidDemo2(); void writeFileDemo3(); int main() { writeFileDemo3(); getchar(); } void writeFileDemo3() { ofstream writeFile("timeUUid.txt", std::ios::app); if (!writeFile) { cout << "Create or open timeUUid.txt failed! " << endl; } stringstream ss; unsigned long long num = 0; for (int i = 0; i < INT16_MAX; i++) { for (int i = 0; i < 100000; i++) { ss << getTimeStringDemo1() << "," << getUuidDemo2() << endl; num++; } writeFile << ss.str() << endl; cout << "Now is " << getTimeStringDemo1() << ",num =" << num << endl; } } string getUuidDemo2() { UUID uuid; UuidCreate(&uuid); char* str; UuidToStringA(&uuid, (RPC_CSTR*)&str); return str; } string getTimeStringDemo1() { time_t rawTime = time(NULL); struct tm info; localtime_s(&info, &rawTime); char str[100]; strftime(str, 100, "%Y%m%d%H%M%S", &info); return str; }
C++ write time string and uuid to file
原文:https://www.cnblogs.com/Fred1987/p/14805906.html