Examveda

What is the output of this C++ program in the "test.txt" file?
#include <fstream>
using namespace std;
int main ()
{
    long pos;
    ofstream outfile;
    outfile.open ("test.txt");
    outfile.write ("This is an apple",16);
    pos = outfile.tellp();
    outfile.seekp (pos - 7);
    outfile.write (" sam", 4);
    outfile.close();
    return 0;
}

A. This is an apple

B. apple

C. sample

D. This is a sample

Answer: Option D


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it