c++ - Code using boost::asio::streambuf causes segfault -


i've experienced problems using asio::streambuf , hoping can tell me if i'm using class incorrectly. when run example code segfaults. why?

to make things more confusing, code works on windows (visual studio 2008), not work on linux (with gcc 4.4.1).

#include <boost/asio.hpp> using namespace std;  int main() {         boost::asio::streambuf stream;          // put 4 bytes streambuf...         int setvalue = 0xaabbccdd;         stream.sputn(reinterpret_cast<const char*>(&setvalue), sizeof(setvalue));          // consume 3 of bytes...         stream.consume(3);         cout << stream.size() << endl; // should output 1          // last byte...         char getvalue;         // --------- next line segfaults program ----------         stream.sgetn(reinterpret_cast<char*>(&getvalue), sizeof(getvalue));         cout << stream.size() << endl; // should output 0          return 0; } 

the way i've used , seen asio::streambuf used std::ostream or std::istream, like:

boost::asio::streambuf stream; std::ostream os(&stream); int setvalue = 0xaabbccdd; os.write(reinterpret_cast<const char*>(&setvalue), sizeof(setvalue)); 

i'm not sure why code doesn't work if above work stepping through may show difference vs. code. line crashing on?


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -