making a void function to reverse the order of a .txt file input by the user

how do you use a void function to reverse the order of a .txt file then print it out?
I just need to see and example of a void reverse_order function
The user has to input the file name earlier in the program to select it (just more info)
Read all the data into an array while recording the number of data points read in. Then call a for loop with a starting value of the number of data points read in decreasing to 0. Within this foor loop have a counter variable going starting @ 0 and increasing by 1 for each iteration of the loop. Then inside this for loop call:

array[counter variable] = array[looping variable]

This will create a new array with all the values in reverse order. Just print this new array and you've got it.
i have a txt file of animals looks similar to this format
species name id date
species name id date
species name id date
species name id date
species name id date
species name id date...

i need to be able to make the bottom line the top and the top line the bottom
Read data from the file into a vector.
Use something like this to reverse the order:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vector<string> lineData;

//Somewhere else load file by line into lineData

void reverse_order()
{
  vector<string> tmp;
  for (int i=(lineData.size()-1); i >= 0; --i)
    tmp.push_back(lineData[i]);

  lineData.clear();
  lineData = tmp;

}


Then just reload the data from the lineData vector into a file2, delete file1, and save file2 as file1.

Last edited on
how do you read it into a vector
Topic archived. No new replies allowed.