i have a file that list all the names and destinations to move the file. so for example a file that looks like this


so as you can see here there are three files that need to be moved in a specific destination. How can i read every two lines and get the name of the file in a string, than the destination as another string? There is no telling how many files there might be it could be 10, 50, 12, 200 who knows. I might not even need vectors for this but i was going to parse a xml file with different information in it.

As i said i was going to parse a xml file and the lines inbetween the tags <newfile> would be like above that is what would be in it. Right now it is just a simple txt file. The code below puts the contents in a vector but i dont know how to read it with increments of 2 since every two lines is a new file and destination. here is what i have.

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

void load_users() {
    std::ifstream d_file("users.txt");
    std::string line;
    std::vector<std::string> user_vec;

    while( std::getline( d_file, line ) ) {
        user_vec.push_back( line );

    // To keep it simple we use the index operator interface:
    std::size_t line_count = user_vec.size();
    for( std::size_t i = 0; i < line_count; ++i ) {
        std::cout << i << "    " << user_vec[i] << std::endl;
    // d_file closes automatically if the function is left

int main()
   return 0;

Instead of ++i, use i = i + 2 in your for statement.

Your problem is number 12 in the while loop. The logic was not right.
try this

string data;
static int count=0;
    data +=line;

you caould have had the data setup the way you want before inserting into the vector. Its called planning.

Instead of ++i, use i = i + 2 in your for statement.

Yeah that is what i needed for this situation thanks.

thank you richieking also you gave me an idea using that code.