saving a text to a text file(need it fast)

i wanna write something a txt file but i dont want it to be overwritten when i run the program again this is my code plz help me thnx


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <ostream>
#include <conio.h>
using namespace std;

int main()
{
    char a;
a='a';

ofstream danainkare;
    danainkare.open("file.txt");

    cout<<"DVD or CD?"<<endl;

   while(a!=13)
   {
           a=getch();
           cout<<a;
        danainkare<<a;
}

    danainkare<<"-";
    a='a';
    cout<<"please write the authors name:"<<endl;
    danainkare<<"author:";

    while(a!=13)
   {
           a=getch();
           cout<<a;
        danainkare<<a;
}
    danainkare<<"-";
    a='a';
    cout<<"please write genre:"<<endl;
    danainkare<<"genre:";

     while(a!=13)
   {
           a=getch();
           cout<<a;
        danainkare<<a;
}
    danainkare<<"-";
    a='a';
    cout<<"please write the year of release:"<<endl;
    danainkare<<"year:";

     while(a!=13)
   {
           a=getch();
           cout<<a;
        danainkare<<a;
}

    return 0;
}
void open ( const char * filename, ios_base::openmode mode = ios_base::out );

So, you can specify how to edit the file, if you wish override of if not

outfile.open ("test.txt",ios::out);

flag value opening mode
app (append) Set the stream's position indicator to the end of the stream before each output operation.
ate (at end) Set the stream's position indicator to the end of the stream on opening.
binary (binary) Consider stream as binary rather than text.
in (input) Allow input operations on the stream.
out (output) Allow output operations on the stream.
trunc (truncate) Any current content is discarded, assuming a length of zero on opening.
cant understand this
just can u tell me where and what to add to my code plz thnx
danainkare.open("file.txt", ios::out | ios::append);
thnx alot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
Topic archived. No new replies allowed.