Como localizar o ponteiro num ficheiro .txt em C++ ?

Krdso

Membro
Boas, estou a tentar criar um ficheiro .txt em C++ e pretendo inserir dados nesse ficheiro, quando insiro a 1ª vez fica lá gravado mas quando vou a inserir pela 2ª vez, o programa escreve por cima do que tinha no ficheiro.

Gostaria que me ajudassem a conseguir escrever a seguir ao que já estáescrito.
 
Bem isto deve ser igual ao C por isso lá vai:

Código:
FILE * fopen (const char * filename, const char * mode);

"r"	Open a file for reading. The file must exist.
"w"	Create an empty file for writing. If a file with the same name already exists its content is erased.
"a"	Append to a file. Writing operations append data at the end of the file. The file is created if it doesn't exist.
"r+"	Open a file for reading and writing. The file must exist.
"w+"	Create an empty file for reading and writing. If a file with the same name already exists its content is erased before it is opened.
"a+"	Open a file for reading and appending.

É só usares o modo que te dá mais jeito :)
 
nao estou a usar esse metodo, estou a usar:

int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
 
Back
Topo