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)
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.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);
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?Code:line1line2
Besides ofstream does anyone see what is wrong with how I am using WriteFile?