Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- void name_file (std::string &input_string1, std::string &input_string2, std::string &output_string);
- void sort_input (std::ifstream &input_file1, std::ifstream &input_file2, std::ofstream &output_file);
- void set_input_name (std::ifstream &input, std::string input_name);
- void set_output_name (std::ofstream &output, std::string output_name);
- void close_file_input(std::ifstream &close);
- void close_file_output(std::ofstream &close);
- int main ()
- {
- std::vector<int> output_vect;
- std::vector<int> potential_next;
- std::ifstream input_file1, input_file2;
- std::ofstream output_file;
- std::string input_filename1;
- std::string input_filename2;
- std::string output_filename;
- name_file(input_filename1, input_filename2, output_filename);
- set_output_name(output_file, output_filename);
- set_input_name(input_file1, input_filename1);
- set_input_name(input_file2, input_filename2);
- sort_input(input_file1, input_file2, output_file);
- close_file_input(input_file1);
- close_file_input(input_file2);
- close_file_output(output_file);
- return 0;
- }
- void name_file(std::string &input_string1, std::string &input_string2, std::string &output_string)
- {
- //name the ouput file
- std::cout << "Including the file extension, please enter the name of the desired output file: ";
- std::cin >> output_string;
- //name the first input file
- std::cout << "What is the name of the first input file? Please include the file extension: ";
- std::cin >> input_string1;
- //name the second input file
- std::cout << "What is the name of the second input file? Please include the file extension: ";
- std::cin >> input_string2;
- }
- void set_input_name (std::ifstream &input, std::string input_name)
- {
- //open file
- input.open(input_name.c_str());
- if (input.fail())
- {
- std::cout << "Error opening input file " << input_name << "." << std::endl;
- }
- }
- void set_output_name (std::ofstream &output, std::string output_name)
- {
- //open file
- output.open(output_name.c_str(), std::ios::app);
- if (output.fail())
- {
- std::cout << "Error opening output file " << output_name << "." << std::endl;
- }
- }
- void close_file_input(std::ifstream &close)
- {
- close.close();
- }
- void close_file_output(std::ofstream &close)
- {
- close.close();
- }
- void sort_input (std::ifstream &input_file1, std::ifstream &input_file2, std::ofstream &output_file)
- {
- //storage for input ints coming from two files
- int num1;
- int num2;
- while((!input_file1.eof()) && (!input_file2.eof()))
- {
- std::cout << "inside the while loop" << std::endl;
- while(!input_file1.eof())
- {
- input_file1 >> num1;
- std::cout << num1 << std::endl;
- }
- while(!input_file2.eof())
- {
- input_file2 >> num2;
- std::cout << num2 << std::endl;
- }
- do
- {
- if(num1 > num2)
- {
- output_file << num2 << " " << std::endl;
- input_file2 >> num2;
- goto next;
- }
- if(num2 > num1)
- {
- output_file << num1 << " " << std::endl;
- input_file1 >> num1;
- goto next;
- }
- if(num1 == num2)
- {
- output_file << num1 << " " << num2 << " " << std::endl;
- input_file1 >> num1;
- input_file2 >> num2;
- }
- next:;
- }while ((!input_file1.eof()) || (!input_file2.eof()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement