I have a c++ program that takes input from a linux pipe, and outputs to std::cout for further processing.
Currently my code looks like this:
std::istreambuf_iterator<char> it(std::cin);
std::istreambuf_iterator<char> end;
std::string str(it, end);
//Lots of string manipulation here.
str = str.substr(0, 65535);
std::cout << str << std::endl;
This is wasteful because the incoming strings are huge.
- How do I only read around 100kB of cin to a c++ string and ignore the rest?
- How can I truncate the c++ string to 65535 bytes instead of characters? (I'll need to handle multi-byte characters in future.)