Apr 5, 2014 at 10:03am UTC
Hi.
How would I make the following into two functions? They would need to rely on each other I suppose and then call the function in main. One function would be for reading the file and the other for assigning the file to the vector. Or should this all be done in one function?
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
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;
int main()
{
ifstream assignFile("document.txt" );
if (!assignFile)
{
cout << "Unable to open file" << endl;
return -1;
}
vector <vector<double > > DocumentVector;
string line;
while (getline(assignfile, line))
{
myVector.push_back(vector<double >());
stringstream input(line);
double value;
while (input >> value)
myVector.back().push_back(value);
}
Last edited on Apr 5, 2014 at 4:50pm UTC
Apr 5, 2014 at 5:14pm UTC
2 functions? I can't imagine what two would do. At present, you done only does 1 thing. It reads the content of the file into some data structure,
So the function would take a filename and return the data structure.
Apr 5, 2014 at 8:20pm UTC
How would you make a single function for this?