Merge file using std::merge

Hi all,

The exercise says we need to merge two text files into a third one suing std::merge. Since that algorithm works only with iterators and only STL containers have iterators, one acceptable solution would be to save the files' contents into two STL containers and then merge the two using std::merge. Finally we can write the merged data back into a third text file.

Last edited on
Apparently, streams can also be iterators.
std::merge assumes sorted inputs. Are you making that assumption about the text files, @frek?

What are you merging? Characters, words, lines, numbers, ...?
Apparently I can't use std::merge with files. The files consist of chars, integers, doubles etc. So I need to make use of an STL container which has begin() and end().
Can you post examples of your files, and what the sort criteria is to determine the ordering.
Texts like these"

Banana Trees
80 Pounds
Jack Sparrow
Jungle surfer
NYC the US

Sony laptops
12 million
Frek troy
C++ developer
Bukan Kurdistan

Toshiba PCes
8 million
Sara Kruze
Java Programmer
London the UK

Asus PCes
11 million dollars
Tony Brown
JavaScript Programmer
WDC the US

Registered users can post here. Sign in or register to post.