alternative to ios::app

I have to do some appending output for a school assignment although was told not to use "ios::app" in the code. Here is the funtion with the ios::app... although I have no idea how to do it otherwise. Any suggestions?

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
void FindWord(char a[], char b[], int count)
{ 
    //define the ofstream and set the operation to append on output
    ofstream outFile;
    outFile.open("Output.txt", ios::app);
    
    int k, j;
    
    //find how long the magic words are
    for(j=0; b[j] != '\0'; j++);
    
    //check to see if the array contains the magic words and note location
    for(int i=0 ; a[i]!='\0' ; i++)                 
    {  
       k=0;
       
       while(a[i+k] == b[k] && k < j && a[i+k] != '\0')
       {
           k++
       }
       
       if (k==j)
       {
                
             //display the where the magic word is found within the line
             cout<<"The magic word \""<<b<<"\" is found at column "
                 <<(i+1)<<" of line "
                 <<count<<"."<<endl;
                 
             outFile<<"The magic word \""<<b<<"\" is found at column "
                 <<(i+1)<<" of line "
                 <<count<<"."<<endl;
       }
       
    }
    
}
You can replace ios::app with 8 which is the numeric value of it (see your implementation of xiosbase).
If you want to avoid automatic casting, use (ios::_Openmode)8
Last edited on
You could also use the constructor of ofstream, it takes a char* and will open the file.
But you have to put there the ios::app (or its equivalents) too
Oh yeah, the pointer goes to the beginning of the file...so you would have to move it to the end after that.
Topic archived. No new replies allowed.