I don't understand why this code gives me error
void printSalesFile(vector< vector<float> > & list) { ofstream outfile; outfile.open("sales.lst", ios::out); if (outfile.is_open()) { outfile << setw(6) << right << "ID" << setw(12) << "January" << setw(12) << "Febuary" << setw(12) << "March" << setw(12) << "April" << setw(12) << "May" << setw(12) << "June" << setw(12) << "July" << setw(12) << "August" << setw(12) << "September" << setw(12) << "October" << setw(12) << "November" << setw(12) << "December" << endl; for (unsigned int i = 0; i <= list.size(); i++) { outfile << setw(6) << right << list[i]; //i don't understand why it says there's an error here. for(int j = 0; j <= 11; j++) outfile << setw(12) << right << list[i][j]; outfile << endl; } } outfile.close(); } I have tried deleting it and pasting the things I wrote above that works but still get the errors.
Here is the error message:
D:\QT\Salesperson\main.cpp:295: error: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&' outfile << setw(6) << list[i]; ^ As for the text file, it has 2 lines, 1 for the header and another that has values all set to 0
list. If you haveusing namespace std;, the compiler is going to be usingstd::listand it gets confused with your variable name.list. In one statement it's a one-dimensional variable, in another, it is a 2 dimensional variable.outfilewith the name of the file:std::ofstream outfile("sales.lst");. And there's no need to check whether it is open; stream inserters can handle a stream that's not in a valid state. And, finally, don't bother toclosethe file: the destructor foroutfilewill do that.