I'm trying to make a program that will open a txt file containing a list of names in this format (ignore the bullets):
- 3 Mark
- 4 Ralph
- 1 Ed
- 2 Kevin
and will create a file w/ organized names based on the number in front of them:
- 1 Ed
- 2 Kevin
- 3 Mark
- 4 Ralph
I'm having trouble outputting the vector into the new file "outfile.txt" On line 198 I get the error "no match for 'operator<<..."
What other methods can I use to output my vector?
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;
struct info
{
int order;
string name;
};
int sortinfo(info a, info b)
{
return a.order < b.order;
}
int main()
{
ifstream in;
ofstream out;
string line;
string collection[5];
vector <string> lines;
vector <string> newLines;
in.open("infile.txt");
if (in.fail())
{
cout << "Input file opening failed. \n";
exit(1);
}
out.open("outfile.txt");
if (out.fail())
{
cout << "Output file opening failed. \n";
exit(1);
}
vector <info> inf;
while(!in.eof())
{
info i;
in >> i.order;
getline(in, i.name);
inf.push_back(i);
}
sort(inf.begin(), inf.end(), sortinfo);
ostream_iterator <info> output_iterator(out, "\n");
copy (inf.begin(), inf.end(), output_iterator);
in.close( );
out.close( );
return 0;
}