#include <iostream> #include <uuid/uuid.h> #include <ostream> #include <istream> #include <fstream> #include <iostream> using namespace std; void retrieveUuid(char *uuidValue); void writeFile2(); void readFile3(); int main() { writeFile2(); readFile3(); return 0; } void readFile3() { fstream wFile; wFile.open("log3.txt",ios::app|ios::in|ios::out); if(!wFile.is_open()) { cout<<"Create or open log3.txt failed!"<<endl; } string uuidValue; int num=0; while(getline(wFile,uuidValue)) { cout<<"Id="<<++num<<",value="<<uuidValue<<endl; } wFile.close(); printf("Finished!\n"); } void writeFile2() { fstream wFile; wFile.open("log3.txt",ios::app|ios::out|ios::in); if(!wFile.is_open()) { cout<<"Create or open log3.txt failed!"<<endl; } char *uuidValue=(char*)malloc(40); for(int i=0;i<10000;i++) { retrieveUuid(uuidValue); wFile<<uuidValue<<endl; } free(uuidValue); wFile.close(); } void retrieveUuid(char *uuidValue) { uuid_t newUUID; uuid_generate(newUUID); uuid_unparse(newUUID,uuidValue); }
Complile and run
g++ -g -std=c++2a h2.cpp -o h2 -luuid
Run the ./h2 command
./h2
Similar Posts:
- C write and read file via FILE and open method in a+ or r mode
- [Solved] C++ get file size via ifstream and set mode as ios::ate
- C++ 11: How to Avoid Deadlock in unique_Lock and lock_Guard
- QT use of undeclared identifier ‘cout’
- [How to Solve]error: invalid array assignment
- [Solved] codeblocks Error: ‘to_string’ was not declared in this scope
- [Solved] OpenCV 4 (C++) Error: “error: ‘CV_FOURCC’ was not declared in this scope”
- [Solved] Clang: error: linker command failed with exit code 1
- How to Solve Const variable assignment Error
- C++ error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m…