i have a file that list all the names and destinations to move the file. so for example a file that looks like this
def.txt
/names/new/
person.obj
/media/people/
panel.jpg
/random/pictures/
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()
{
load_users();
system("PAUSE");
return 0;