How to make it so that you can record several times in the file information. Below is a code that writes only once from the keyboard to file A, and then reads the text from file B and also writes to file A

#include "stdafx.h" #include <iostream> #include "windows.h" #include <fstream> #include <string> using namespace std; HANDLE hMutex; ofstream in("D:\\A.txt"); ifstream out("D:\\B.txt"); char rdbuf[100]; DWORD WINAPI Thread(void* pParams) { WaitForSingleObject(Thread, INFINITE); out.getline(rdbuf, 100); in << rdbuf << endl; out.close(); ReleaseMutex(Thread); return 0; } int main(void) { HANDLE thread = CreateThread(NULL, 0, Thread, NULL, 0, NULL); hMutex = CreateMutex(NULL, FALSE, NULL); WaitForSingleObject(hMutex, INFINITE); cout << "Enter string - "; string a; getline(cin, a); in << a; in.close(); ReleaseMutex(hMutex); return 0; } 

    0