This program is supposed to read in a data file, organize the data into a vector, and then write the vector into a new file.
My code:
CODE
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
ifstream fin; // declare an input file stream
string file_name, out_stream;
double x;
cout << "Enter file name: ";
cin >> file_name;
// open file file_name for input
fin.open(file_name.c_str(), ios::in);
// check if file is opened for input
if (!fin.is_open())
{
cerr << "Unable to open file " << file_name << endl;
exit(10);
}
// read text from file
vector<double> v;
fin >> x;
while (!fin.eof() && !fin.fail()) {
v.push_back(x);
fin >>x;
}
if (!fin.eof() && fin.fail()) {
cerr << "Error reading file " << file_name << endl;
exit(20);
}
else if (fin.eof() && !fin.fail()) {
v.push_back(x);
}
// close file stream fin
fin.close();
//sort vector
sort(v.begin(), v.end());
cout << v <<endl;
return 0;
//Step6?
ofstream fout;
// open file file_name for output
// out_stream.c_str() returns a C style string
fout.open(out_stream.c_str(), ios::out);
// check if file is opened for output
if (!fout.is_open())
{
cerr << "Unable to open file " << file_name << endl;
exit(10);
}
// write vector to file
fout<< v <<endl;
// close file stream fout
fout.close();
return 0;
}
when i try to compile this I get the error "
no match for `std::ostream& << std::vector<double,
std::allocator<double> >&' operator". I have no idea what this means.