Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- int main(int argc, const char *argv[])
- {
- if (argc <= 2)
- {
- cerr << "Usage: " << argv[0] << " FILENAME1 FILENAME2 [FILENAME3 [FILENAME4 [...]]\n";
- return -1;
- }
- auto lists = new vector<string> [argc-1];
- for (int i=1; i<argc; i++)
- {
- ifstream file(argv[i]);
- if (!file.good())
- {
- cerr << "Error openening file \"" << argv[i] << "\"\n";
- return -1;
- }
- lists[i-1].clear();
- string line;
- while (getline(file, line))
- {
- int length = line.length();
- if (line[length-1] == '\n')
- length--;
- if (line[length-1] == '\r')
- length--;
- lists[i-1].push_back(line.substr(0, length));
- }
- }
- auto current = new int [argc-1];
- for (int i=0; i<argc-1; i++)
- current[i] = 0;
- for (;;)
- {
- for (int i=0; i<argc-1; i++)
- {
- cout << lists[i][current[i]];
- if (i < argc-2)
- cout << ' ';
- }
- cout << endl;
- for (int j=argc-2;;)
- {
- if (++current[j] < lists[j].size())
- break;
- current[j] = 0;
- if (--j < 0)
- return 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment