I have a input file (.txt). It has a list of books in the format:
catalogue_number, author_last_name,author_first_name, book_title, genre, availabilty
* The catalogue is 4 characters long
It needs to sort the author_last_name from the input file using array and output as an .txt file.
HOW DO I DO THIS???? I'M VERY CONFUSED.
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;
}
You don't have to explictly specify a size for the array, you just have to pass a pointer to the array end to std::sort (you can use sizeof to figure out the array size).