output numbers in ascending order?

How can I get input numbers to correctly arrange themselves in ascending order no matter what? example. 1, 2, 3, 4, 5, 6 in my output

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116`` ``````#include #include #include #include using namespace std; int main() { ifstream fin1, fin2; ofstream fout; fin1.open("numbers1.txt"); if(fin1.fail()) { cout << "Input file opening failed." << endl; exit(1); } fin2.open("numbers2.txt"); if(fin2.fail()) { cout << "Input file opening failed." << endl; exit(1); } fout.open("output.txt"); if(fout.fail()) { cout << "Output file opening failed." << endl; exit(1); } int number1, number2; fin1 >> number1; fin2 >> number2; do { if(number1 == number2) { fin1 >> number1; fin2 >> number2; fout << number1 << endl; fout << number2 << endl; } if(number1 > number2) { fin2 >> number2; fout << number2 << endl; } if(number2 > number1) { fin1 >> number1; fout << number1 << endl; } }while(!fin1.eof() && !fin2.eof()); while(!fin2.eof()) { fin2 >> number2; fout << number2 << endl; } while(!fin1.eof()) { fin1 >> number1; fout << number1 << endl; } if(fin1.eof()) { if(number2 > number1) { fout << number1 << endl; } if(number1 > number2) { fout << number1 << endl; } if(number1 == number2) { fout << number1 << endl; } } if(fin2.eof()) { if(number2 > number1) { fout << number2 << endl; } if(number1 > number2) { fout << number2 << endl; } if(number1 == number2) { fout << number2 << endl; } } fin1.close(); fin2.close(); fout.close(); return 0; }``````
Posting a question in all the forums will not help. Neither will posting the same question in different ways.
People here visit all the forums and check all the posts and try to answer them if they can.

So, be patient and your issues will be solved. :-)
You want to output all numbers from two foies in ascending order?
Like file1: 1, 3, 2; file2: 6, 5, 4; output: 1, 2, 3, 4, 5, 6?

If so, you need to load numbers from both files into array, sort them and then output to file.
Topic archived. No new replies allowed.