How can I save all the output in txt file? My program needs to automatically loa
ID: 3720108 • Letter: H
Question
How can I save all the output in txt file?
My program needs to automatically load data at the beginning and save data back to the file at the end. Please don't prompt user for data file name.
Here's how my main.cpp source code looks like
----------------------------------------------
// main.cpp
#include "p1.cpp"
#include <iostream>
int main()
{
joonLabel jl;
jl.addArtist();
cin.ignore(0);
jl.addSong();
cin.ignore(1000, ' ');
jl.addArtist();
cin.ignore(0);
jl.addSong();
cin.ignore(1000, ' ');
jl.addSong();
cin.ignore(0);
jl.disArtist();
cin.ignore(1000, ' ');
jl.disSong();
cin.ignore(0);
jl.editVL();
cin.ignore(1000, ' ');
jl.rmSongsWithV();
cin.ignore(1000, ' ');
jl.disSong();
cin.ignore(0);
jl.disArtist();
return 0;
}
Explanation / Answer
class joonLabel
{
private:
char Artist[100];
char Song[200];
Public:
joonLabel()
{
ofstream outfile;
outfile.open("sample.dat");
}
~joonLabel()
{
inFile.close;
}
addArtist()
{
char data[100];
cout << "Enter Artist: ";
cin.getline(data, 100);
// write inputted data into the file.
outfile << data<<" ";
}
addSong()
{
char data[100];
cout << "Enter Song: ";
cin.getline(data, 100);
// write inputted data into the file.
outfile << data<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.