I need to write some text at the end of txt file. But i can only rewrite all file. How can i add text to the end of file?
Thank you.
Are you sure you are opening the file in the append mode? QIODevice::Append
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
size_t count;
const char *str = "hello\n";
fp = fopen("yourFile.txt", "a");
if(fp == NULL) {
perror("failed to open yourFile.txt");
return EXIT_FAILURE;
}
count = fwrite(str, 1, strlen(str), fp);
printf("Wrote %u bytes. fclose(fp) %s.\n", count, fclose(fp) == 0 ? "succeeded" : "failed");return EXIT_SUCCESS;}
Just use the append "a" flag!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With