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.

Agree?
Last edited on
Apparently, streams can also be iterators.
https://en.cppreference.com/w/cpp/iterator/istream_iterator
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
123
Jack Sparrow
Jungle surfer
NYC the US

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

Toshiba PCes
8 million
32
Sara Kruze
Java Programmer
London the UK

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

Topic archived. No new replies allowed.