Hello, i am making a basic program and I need to create a new file and add a couple lines to it. (C++)
I have tried something similar to this, with writefile (WriteFile Function (Windows))
(i dont have the code with me but this is the gist of it)
Code:
string buffer = "line1\nline2";
HANDLE hf = CreateFile( ..... ); // open with write attribute, Create_always
LPDWORD lpNumberOfBytesWritten;
WriteFile(hf, buffer.c_str(), buffer.length(), lpNumberOfBytesWritten, NULL);
For some reason this code ALWAYS skips the newline character in the buffer, and the file ends up containing the following, which screws up the rest of my program.
Now I am sure that ofstream won't let me down if I use it, but I was wondering if theres any disadvantage to using ofstream opposed to WriteFile since I am only using basic options. This is a windows program, would I run into any problems using ofstream?
Besides ofstream does anyone see what is wrong with how I am using WriteFile?
thanks!