I keep getting this error code It builds the code but when i run it, it just crashes it says "the stack around the variable 'names' was corrupted.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream outputfile;
const char CDTitle = 50;
char names[CDTitle];
int count, count2;
const char Artist = 50;
char art[Artist];
int play_length, choice;
//store values in the array
for (count = 0; count < CDTitle; count++)
names[count] = count;
for (count2 = 0; count2 < Artist; count2++)
art[count] = count2;
//open an output file.
outputfile.open("MP3 List.txt");
//get the information of the mp3 from the user
cout << "Enter the CD title: ";
cin >> names[CDTitle];
cout << "Enter the artist: ";
cin >> art[Artist];
cout << "Enter the play length of the song: " << endl;
cin >> play_length;
//write the information to the file.
outputfile << names[CDTitle] << endl;
outputfile << art[Artist] << endl;
outputfile << play_length << endl;
cout << "The file was saved to MP3 list.txt.\n" << endl;
// Close the file
outputfile.close();
cout << "Done and stored.\n" << endl;
return 0;
// Constants for menu choices
const int MP3_choice = 1,
Modify_choice = 2,
Print_choice = 3,
Save_choice = 4,
Retrieve_choice = 5,
Quit_choice = 6;
//Display the interface and get a choice
cout << "\t\tMP3 Menu\n\n"
<< "1. Add MP3\n"
<< "2. Modify a MP3 file\n"
<< "3. Print out MP3 list\n"
<< "4. Save List\n"
<< "5. Retrieve List\n"
<< "6. Quit Program\n"
<< "Enter your choice: ";
cin >> choice;
//Respond to the user's menu selection
if (choice == MP3_choice)
{
cout << "Enter the CD Title: ";
cin >> names[CDTitle];
cout << "Enter the artist: ";
cin >> art[Artist];
cout << "Enter the play length of the song: " << endl;
cin >> play_length;
//write the information to the file.
outputfile << names[CDTitle] << endl;
outputfile << art[Artist] << endl;
outputfile << play_length << endl;
cout << "The file was saved to MP3 list.txt.\n" << endl;
}
else if (choice == Modify_choice)
{
cout << "For what mp3 file do you want to modify ";
cin >> names[CDTitle] >> art[Artist];
cout << "Enter the new cd name:\n ";
cin >> names[CDTitle];
cout << "Enter the new artist:\n ";
cin >> art[Artist];
cout << "Enter the duration:\n ";
cin >> play_length;
//write the information to the file.
outputfile << names[CDTitle] << endl;
outputfile << art[Artist] << endl;
outputfile << play_length << endl;
cout << "The file was saved to MP3 list.txt.\n" << endl;
}
else if (choice == Print_choice)
{
cout << "Which MP3 do you want to print out? ";
cout << names[CDTitle] << art[Artist] << play_length << endl;
}
else if (choice == Save_choice)
{
cout << "Which file do you want to save? ";
outputfile << names[CDTitle] << endl;
outputfile << art[Artist] << endl;
outputfile << play_length << endl;
cout << "The file was saved to MP3 list.txt.\n" << endl;
}
else if (choice == Retrieve_choice)
{
cout << "Which file do you want to retrieve? Please enter a valid file ";
cin >> names[CDTitle] >> art[Artist] >> play_length;
}
else if (choice == Quit_choice)
{
cout << "Program ending.\n";
}
else
{
cout << "The valid choices are 1 through 6. Run the\n"
<< "program again and select one of those.\n";
}
return 0;
}