I have a program that writes out the frame number and current system time whenever a picture is taken on a camera:

```
SYSTEMTIME st;
GetSystemTime(&st);
lStr.Format( _T("%d   %d.%d.%d.%d\r\n"),GetFrames() ,st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);

std::wfstream myfile;  
myfile.open("test.txt", std::ios::out | std::ios::in | std::ios::app );
    if (myfile.is_open())
            {
            myfile.write((LPCTSTR)lStr, lStr.GetLength()*sizeof(TCHAR));
            myfile.close();
            }
        else {lStr.Format( _T("open file failed: %d"), WSAGetLastError());
        }

```

The text file that the program outputs seems to write the data correctly, but I get spaces and characters that shouldn't be there at the start of each line. The website doesn't seem to format the spaces correctly so i'll post a picture, this is what the text file looks like. The file also shows bullet points sometimes in addition to the zero's.

[![enter image description here](https://i.stack.imgur.com/Q1BTG.png)](https://i.stack.imgur.com/Q1BTG.png)

As you can see the first line is fine but it seems to get worse the longer I write to the text file. The program is writing to the file about 10 times every second. I am new to C++ and I am not sure what could be causing this. I tried to look for other questions similar to this but they didn't seem to have a solution I was looking for. Any help would be appreciated.