Answer to Question #192128 in C++ for Deeptesh

Question #192128

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".


1
Expert's answer
2021-05-11T14:00:11-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment