Read whole ASCII file into C++ std::string

There are a couple of possibilities. One I like uses a stringstream as a go-between: Now the contents of “file.txt” are available in a string as buffer.str(). Another possibility (though I certainly don’t like it as well) is much more like your original: Officially, this isn’t required to work under the C++98 or 03 standard (string … Read more

Is there a maxheap in the C++ standard library?

Regarding std::priority_queue: A user-provided Compare can be supplied to change the ordering, e.g. using std::greater<T> would cause the smallest element to appear as the top(). Since std::less<T> is the default template argument to the Compare template parameter, it is already a max heap by default. If you want a min heap instead (what the quote above suggest), pass std::greater<T> instead of std::less<T> as the template argument. To summarize: Max Heap: pass std::less<T> (this is the default template … Read more

tech