input/output and arrays

I have an interface (.cpp),header(.h) and implementation(.cpp)
The interface does the input/output.
The header writes the class and it's member functions:
The implemetation does the sorting.
My input file (.txt)is a list of books in the format:
catalogue_number, author_last_name,author_first_name, book_title,genre,availabilty.
*The catalogue number are 4 digits.
I need to sort the author_last_name using an array and output in file(.txt)

I needed help seperating into the three files, outputing and inputing from the file and using arrays to sort rather than vector.
#include <iostream>
#include <iterator>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <fstream>
using namespace std;
class SBooks {
private:
string catalogue_number;
string author_first_name;
string author_last_name;
string book_title;
string strGenre;
string strAvail;
public:
friend bool comp(const SBooks& a, const SBooks& b)
{
return a.author_last_name < b.author_last_name ? true : false;
}

friend ostream& operator<<(ostream& os, const SBooks& s)
{
os << setw(6) << s.catalogue_number << setw(15) << s.author_first_name << setw(15) << s.author_last_name << setw(20) << s.book_title << setw(10) << s.strGenre << setw(14) << s.strAvail;
return os;
}
friend istream& operator>>(istream& is, SBooks& s)
{
is >> s.catalogue_number >> s.author_last_name >> s.author_first_name >> s.book_title >> s.strGenre >> s.strAvail;
return is;
}
};

bool comp(const SBooks& a, const SBooks& b);

int main()
{
const string strFile = "input2.txt";
ifstream is(strFile.c_str());
vector<SBooks> vInput;
// This copies SBook objects into a vector from file input.txt
copy(istream_iterator<SBooks>(is), istream_iterator<SBooks>(), back_inserter(vInput));
cout << "Read in records unsorted: \n";
// This prints the read in output to the screen.
copy(vInput.begin(), vInput.end(), ostream_iterator<SBooks>(cout, "\n"));
// This performs the sorting
sort(vInput.begin(), vInput.end(), comp);
// This prints the sorted output to the screen.
cout << "Sorted: \n";
copy(vInput.begin(), vInput.end(), ostream_iterator<SBooks>(cout, "\n"));
return 0;
}
Please if anyone could help me.
Topic archived. No new replies allowed.