C++: How do I route file input stream to cout in one statement? inputStream >> cout doesn't work

Viewed 49

How do I take output from a stream and link directly into cout.

For example: inStream >> cout... This doesn't actually work through. PLZ HELP

1 Answers

I think rdbuf() helps you:

#include <iostream>
#include <sstream>
#include <fstream>
int main()
{
    std::istringstream input{ "Some content" };
    std::cout << input.rdbuf();
    std::ifstream file{ R"(b:\test.txt)" };
    std::cout << file.rdbuf();
}
Related