I am trying to store the Title, Artist, and date published of a list of CD's. I can't seem to be able to get it to print the list or not sure if it is actually storing it. This is what i have so far... any help would be appreciated.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
usingnamespace std;
int main()
{
char names[5][100];
for (int i = 0; i < 5; i++)
{
cout << "Title of DVD, Date created, Producer:\n";
cin.getline(names[i], 99);;
}
ifstream inFile;
ofstream outFile;
char response;
inFile.open("CD.txt");
if (!inFile.fail()) {
cout << "A file by the name CD.txt exists.\n"
<< "Do you want to continue and overwrite it\n"
<< " with the new data (y or n): ";
cin >> response;
if (tolower(response) == 'n') {
cout << "The existing file will not be overwritten." << endl;
exit(1);
}
}
outFile.open("CD.txt");
if (inFile.fail()) {
cout << "\nThe file was not successfully opened" << endl;
exit(1);
}
cout << "The file has been succesfully opened for writing." << endl;
ofstream myfile ("CD.txt");
if (myfile.is_open())
{
myfile << char names [5][100] << endl;
myfile.close();
}
else cout << "Unable to open file";
return 0;
}