Answer to Question #213905 in C++ for ismail khan

Question #213905

Assuming we have following variables and values:

int a=5, b=10, c=15, x, y, z;

Write the values of a, b and c variables in file by using formatted file I/O and then read data accordingly from file and assign it to x, y and z variables. Just create objects of relevant classes, there is no need to write entire main function.



1
Expert's answer
2021-07-05T13:28:52-0400
#include <iostream>
#include <fstream>
using namespace std;


int main()
{
    int a=5, b=10, c=15, x, y, z;
    ofstream out ("text.txt");
    out<<"\na= "<<a;
    out<<"\nb= "<<b;
    out<<"\nc= "<<c;
    out.close();
    
    ifstream in("text.txt");
    string n;
    while (getline (in, n)) {
  // Output the text from the file
        cout<<n;
    in.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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS