Hello everybody I'am trying to open a File with an Filedeskriptor. After Opening the file I want to append Data to the File!
I have the following code now, but I only overwrite the data from the file and did not append it!
I hope somebody please could help me!
I have the following code now, but I only overwrite the data from the file and did not append it!
Code:
void Buffer::writeIntoFile(std::string name, int length, std::string text){
int fd;
FILE *fp;
std::ofstream ofs;
if((fd = open(name.c_str(),(O_CREAT|O_WRONLY|O_RDONLY))) < 0){
cout << "Error Opening File\n";
}
if((fp = fdopen(fd,"a")) < 0){
cout << "Error\n";
close(fd);
}
//Create a Filebuffer from File
__gnu_cxx::stdio_filebuf<char> fb(fp,std::ios::out);
ofs.std::ios::rdbuf(&fb);
ofs << text<< endl;
ofs.close();
}
I hope somebody please could help me!