Creating functions with Vectors

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
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.
How would you make a single function for this?
Topic archived. No new replies allowed.