Jul 10, 2019 at 9:13am UTC
how to print out the contents of the vector? I have stored the contents of a file into a vector that also connects to a class, is it easier to print out a vector or print out the contents of a class? If there is anything else that I could fix, please let me know.Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;
class expense
{
public :
double c_price;
string c_discription;
string toString()
{
stringstream sout;
sout << "price $(" << c_price << ") discription(" << c_discription << ")" ;
return sout.str();
}
};
int main(int argc, char *argv[])
{
fstream fin;
fin.open("expenses2.txt" , ios::out);
if (!fin)
{
cerr << "Error in opening the file" << endl;
return 1;
}
vector<expense> expenses1;
expense temp;
while (fin >> temp.c_price >> temp.c_discription)
{
expenses1.push_back(temp);
}
string command;
cout << "spend\nshow\namount >=\nsave file\nhelp\nexit" << endl;
cin >> command;
if (command =="show" )
{
copy(expenses1.begin(), expenses1.end(), ostream_iterator<int >(cout, " " ));
}
else if (command == "help" )
{
menu();
}
else if (command == "spend" )
{
}
cout << argc << " " << boolalpha << argcCheck(argc) << endl;
if (argcCheck(argc) == false )
{
cout << "invalid command, please try again" << endl;
}
return 0;
}
Last edited on Jul 10, 2019 at 9:35am UTC