Problems inserting text in a txt file

Hi, im having problems trying to insert a text into a txt file in the end of the text file, example:


inside asuna.txt

This is the world

and im trying to do:

inside asuna.txt

This is the world where i am alive.((or something like that)

I am using seekp but i dont know why it didnt work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(){
char eska[100];
char desna[100];
char p[100]="where i belong";
fstream out("asuna.txt",ios::in|ios::out|ios::binary);
out.read((char*)&eska,sizeof eska);
for(int a=0;a<out.gcount();a++)cout<<eska[a];
out.seekp(eska[out.gcount()+2],ios::beg);
out.write((char*)&p,sizeof p);
out.read((char*)&eska,sizeof eska);
for(int a=0;a<out.gcount();a++)cout<<eska[a];
out.close();

system("pause");
return 0;
}
Have you tried using seekp() with ios::end instead?
thank you
Topic archived. No new replies allowed.