So what I'm supposed to do is take a text file and read it into a set of string vectors. The file has three types of data in it, in this order: title, artist, genre. I need to read it into the vectors so that each data type is only read into its specific vector (vector<string> title, vector<string> artist, vector<string> genre).
I'm new at C++, so I guess I'm looking for a little guidance. I know I need to use some type of loop. I was thinking that I would keep track of how many loops occur, and divide by three to tell the program how to read in genre. But the problem is, obviously, if i do divide by two and one that, that will also read in the wrong data types to the wrong vector.
here is my code so far:
#include <iostream> // For input and output to the monitor
#include <fstream> // For file input and output (given)
#include <string> // For text data
#include <vector> // library for using vectors
using namespace std; // To make is easier put this in global namespace
void addsong(vector<string>, vector<string>, vector<string>);
// function: this adds songs to the library
// parameters: string title, string artist, string genre
// functionality: prompts the user for the parameters and checks to make sure
// the song isn't already in the library
int main()
{
vector<string> title;
vector<string> artist;
vector<string> genre;
ifstream in_stream;
ofstream out_stream;
int i = 1;
int j = 0;
in_stream.open("music_library.txt");
out_stream.open("outmusic_library.txt");
while(!in_stream.eof())
{
i++;
if(i%3==0);//will read every third line into genre vector?
{
in_stream >> genre[j];
j++;
}
}
int choice;
do
{
cout << "1. Add a new song\n";
cout << "2. Remove an existing song\n";
cout << "3. Search for a song\n";
cout << "4. Quit program\n";
cin >> choice;
switch(choice)
{
case 1: //user wants to add a song
addsong(title, artist, genre);
break;
case 2: //user wants to remove an existing song
break;
case 3: //user wants to search for a song
break;
case 4: //user wants to quit program
cout << "GOODBYE!\n";
break;
}
}while(choice !=4);
in_stream.close( );
out_stream.close( );
return 0;
}
void addsong(vector<string> title, vector<string> artist, vector<string> genre) // unfinished
{
string t_title, a_artist, g_genre;
cout << "Enter the title name: " << endl;
cin >> t_title;
cout << "Enter the artist name: " << endl;
cin >> a_artist;
cout << "Enter the genre: " << endl;
cin >> g_genre;
}