Thread: String buffer to streambuffer

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    99

    String buffer to streambuffer

    Dear experts,

    please tell me is anyway of converting a string buffer into stream buffer.

    i desperately need this for my project.
    i want to convert from
    Code:
    char *buffer;(some contents)
    
    strembuf *buf=buffer;
    is this is possible is there any way please help me.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What is strembuf?

  3. #3
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Quote Originally Posted by Daved
    What is strembuf?
    There are three possibilities:
    1. A class
    2. A structure
    3. A type

    @vin_pll: We can't know if char* is convertable to streambuf if we don't know what it is (one of the three above). If it's a type then casting (streambuf*) is needed (at least in C++).

    Code:
    char *buffer;(some contents)
    
    strembuf *buf=(strembuf*)buffer;
    Last edited by hauzer; 11-10-2008 at 05:29 AM.
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by vin_pll View Post
    Dear experts,

    please tell me is anyway of converting a string buffer into stream buffer.

    i desperately need this for my project.
    i want to convert from
    Code:
    char *buffer;(some contents)
    
    strembuf *buf=buffer;
    is this is possible is there any way please help me.
    actually, in this case, the streambuf (i'm only guessing here, but I suspect you're talking about an std::streambuf) does not need to be a pointer. you can do the following:
    Code:
    #include <iostream>
    
    char buffer[] = "this is a string";
    std::streambuf *buf = new std::stringbuf(buffer);
    std::streambuf is a pure virtual class and cannot be instantiated by itself. you have to use std::filebuf or std::stringbuf, or perhaps a custom class derived from it.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    99
    thank you experts,
    for giving your suggestion,

    but none of them is working
    Code:
    strembuf *buf=(strembuf*)buffer;
    
    i tried to cast this but no result is there any way to print the output(buf) here,
    
    and also
    
    std::streambuf *buf = new std::stringbuf(buffer);
    
    this is giving me a error like no constructor is defined
    is there any other possiblities so that i cast and display the contents if it is successfull.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Did you #include <streambuf> and <sstream>?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM