Write a program to open a file gr.txt.Add these contain "My name is XYZ"and afterwards and "How are you".Shift file pointer in such a way that final content in the file is "My name is How are you".
#include <iostream>
#include <fstream>
using namespace std;
int main(){
fstream file;
file.open("gr.txt", ios::out | ios::trunc);
if(file){
file<<"My name is XYZ";
file.seekp(0, ios::end);
file<<" How are you";
}
else cout<<"Error opening file";
file.close();
return 0;
}
Comments
Leave a comment