I'm attempting to divide a vector into two distinct arrays. A text file's current int vector has one element per line. There is a list of random integers in the text file.
How I intend to approach it:
Right now, I'm thinking of making two ordinary int arrays, iterating over the whole vector, and copying n/2 elements to each array.
What I want to know is:
What is the classiest way to complete my task? I believe I can accomplish this without repeatedly iterating over the vector.
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
using namespace std;
vector<int> ifstream_lines(ifstream& fs)
{
vector<int> out;
int temp;
while(fs >> temp)
{
out.push_back(temp);
}
return out;
}
vector<int> MergeSort(vector<int>& lines)
{
int split = lines.size() / 2;
int arrayA[split];
int arrayB[split];
}
int main(void)
{
ifstream fs("textfile.txt");
vector<int> lines;
lines = ifstream_lines(fs);
return 0;
}