I'm getting an undeclared error in my main program at line 45. Can anyone find out what is causing it?
Main
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <vector>
#include "playlist.h"
using namespace std;
int main (int argc, char*argv[])
{
ifstream fin;
int lineCounter = 1;
string parsedLine[NUM_OF_FIELDS];
vector <Song> song;
unsigned int i;
string line;
if (argc != 2)
{
cout <<"Wrong number of arguments.\n";
exit(1);
}
//Open file specified on command line.
fin.open (argv[1]);
//If it cannot open the file exit the program.
if (fin.fail())
{
cout <<"Could not open the input file. \n";
exit(1);
}
getline(fin,line);
while (getline(fin,line ))
{
lineCounter++;
if(! parseLine(line, parsedLine) )
{
cerr <<"Error: invalid line in file " <<argv[1] <<" at line " <<lineCounter <<"\n\n";
}
else
{
Song newsong(parsedline[TITLE], parsedline[ARTIST], parsedline[ALBUM], parsedline[GENRE],
parsedline[SIZE],parsedline[TIME],parsedline[COMMENT]);
song.push_back(newsong);
}
for (int i = static_cast <int> (ARTIST); i < static_cast<int> (NUM_OF_FIELDS); i++)
{
parsedLine[i].clear();
}
}
for (i = 0; i < song.size(); i++)
{
song.at(i).print(cout);
}
cin.get();
return 0;
}
playlist class
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum FIELD {TITLE=0, ARTIST, ALBUM, GENRE, SIZE, TIME, COMMENT, NUM_OF_FIELDS};
//This class is used to store the song information information read from the file.
class Song
{
public:
Song (string title2, string art, string alb, string gen, string siz, string tim, string comm);
void print ( ostream & out );
private:
string title;
string artist;
string album;
string genre;
string size;
string time;
string comment;
};
bool parseLine(string line, string parsedLine[]);
#endif
playlist.cpp
#include "playlist.h"
Song::Song (string title2, string art, string alb, string gen, string siz,
string tim, string comm)
:title(title2),artist(art),album(alb),genre(gen),size(siz),
time(tim),comment(comm)
{ }
bool parseLine( string line, string parsedLine[] )
{
int start = 0, end = -1; //indecis for start and end of the field on the line
if (line.size() <= 2* NUM_OF_FIELDS)
return false;
for(unsigned int next = static_cast <unsigned int> (TITLE); next < static_cast<unsigned int> (NUM_OF_FIELDS) ; next++)
{
start = line.find_first_not_of(" \t", end+1);
if (start != string::npos )
end = line.find_first_of("\"", start+1);
else
return false;
if (end != string::npos && line[start] == '"' )
{
start++;
parsedLine[next] = line.substr(start, end-start);
}
else
return false;
}
if( end != line.size()-1 && line.find_first_not_of(" \t\r", end+1) !=string::npos )
return false;
if (parsedLine[0].size() == 0 || parsedLine[1].size() == 0)
return false;
//if we got here, the line contains a valid input and parsedLine has values of all the fields
return true;
}
void contact::print ( ostream & out )
{
out <<title <<", "<<artist <<", " <<album <<", " <<genre <<", " <<size << ", " <<time << ", " <<comment <<"\n";
}