I was testing how to read data out of an std::streamstring but I'm getting it wrong, could anyone point out what's the problem? and give a correct way to read it?
My testing code is:
#include <iostream> #include <string> #include <sstream> #define BUFFER_SIZE 16 int main(int argc, char ** argv) { std::stringstream ss; ss << "Un texto con datos de ejemplo para probar la extacción de un stream"; std::cout << "Stream contents: '" << ss.str() << "'" << std::endl; char buffer[BUFFER_SIZE] = {0}; std::streamsize read = 0; do { read = ss.readsome(buffer, BUFFER_SIZE - 1); std::cout << "Read: " << ss.gcount() << std::endl; std::cout << buffer << std::endl; std::cout << "---" << std::endl; std::fill(buffer, buffer + BUFFER_SIZE, 0); } while ( read > 0 ); return 0; } And I'm getting the output:
Stream contents: 'Un texto con datos de ejemplo para probar la extacci¾n de un stream' Read: 15 Un texto con da --- Read: 15 tos de ejemplo --- Read: 15 para probar la --- Read: 15 extacci¾n de un --- Read: 5 stre --- Read: 0 --- As you may notice the last read operation reads only 5 characters leaving out the last two 'am' even though it should have been able to read it. Am I missing somtehing?
wchar_tversion of streams and strings.ówith a regularoresult in the same result. Why would I need to work withwchar_tanyway?