How about
std::istreambuf_iterator<char> eos;
std::string s(std::istreambuf_iterator<char>(stream), eos);
(could be a one-liner if not for MVP)
post-2011 edit, this approach is now spelled
std::string s(std::istreambuf_iterator<char>(stream), {});
More Related Contents:
- How to create string of strings in c++
- String comparison operators
- How do I iterate over the words of a string?
- What is the type of string literals in C and C++?
- Replace part of a string with another string
- C++ deprecated conversion from string constant to ‘char*’
- Why does omission of “#include ” only sometimes cause compilation failures?
- Right way to split an std::string into a vector
- changing the delimiter for cin (c++)
- How is std::string implemented?
- How do I concatenate multiple C++ strings on one line?
- How to return a std::string.c_str()
- C++ Compare char array with string
- How to read file content into istringstream?
- Error: invalid operands of types ‘const char [35]’ and ‘const char [2]’ to binary ‘operator+’
- How to strip all non alphanumeric characters from a string in c++?
- cannot convert ‘std::basic_string’ to ‘const char*’ for argument ‘1’ to ‘int system(const char*)’
- Counting the number of occurrences of a string within a string
- C++: Can a macro expand “abc” into ‘a’, ‘b’, ‘c’?
- What is the datatype of string literal in C++?
- Converting bool to text in C++
- Converting an int to std::string
- Do I have to use #include beside ?
- Braces around string literal in char array declaration valid? (e.g. char s[] = {“Hello World”})
- Using std::string_view with api that expects null-terminated string
- Fastest way to Convert String to Binary?
- cin.getline() is skipping an input in C++ [duplicate]
- C++ Extract number from the middle of a string
- C++ Passing std::string by reference to function in dll
- Concatenate compile-time strings in a template at compile time?