atoi/sprintf are totally unnecessary; the stream overloads are just fine.
While sorting vector or using multiset would produce expected output, is that the goal? Or the beef in the logic?
You seem to start well. Then you reach the point, where one or both streams are at end and the latest number from each has not been output. If they are equal, both should be written. If not, one stream still may have values and the challenge is to insert the value of the exhausted stream at correct position.
How about a function that reads from one stream and inserts "pivot value" when suitable. Then call that function with appropriate input.