Thread: Trouble with I/O

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Prelude
    >so that leaves me with get()/put() or using streambuf with rdbuf()?
    Let's just sidestep the entire issue, k?
    Code:
    // Copy the contents of in to out:
    out<< in.rdbuf();
    Alright cool, but even with streambuf's constructor being protected, its still better to use << for binary? Which I'm assuming formats also..

    Streambuf works well, and VC++ no longer complains now that you corrected my mistake.. but it is a lot more code than <<, but I could make a function (or operator overload) for it if its a better method for binary than inserters.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but even with streambuf's constructor being protected
    This has nothing to do with it. As long as you use streambuf pointers, you won't encounter this issue unless you have a need for the constructor in a custom stream of your own design. Since you aren't likely to need a custom stream for a while, you can forget about the constructor for streambuf and how it isn't public.

    >its still better to use << for binary?
    Okay, a streambuf only understands characters, so passing a streambuf to operator<< is identical in concept to passing a char to operator<<. Formatting is irrelevant. Passing a streambuf to operator<< is the most expedient (and usually the most efficient) way to copy the contents of an input stream to an output stream.
    My best code is written with the delete key.

  3. #3
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Ohhh yeah, I dont even think about these things when im using libraries (its easier to relate to to it when its my own code). I should have caught onto that about the constructor when you said it. Thanks Prelude.

    Thanks guys its working

    Edit: Feeling really slow here, you meant Dev-Cpp was in the wrong because of the error I had by putting the pointers on the same line, which caused it to make an actual object instead of a pointer, which should not be able call the constructor because its protected. But it did allow me to use the protected constructor since it compiled, and hence is the fault of Dev-Cpp.

    And of course.. you input less than a byte so of course its going to import 1 byte (1 char) at a time, then format it into binary, so thats why it doesnt matter if I use <</>> that are formatted (for some reason I was thinking you would be importing 8 * 1/0's, which would be more than 1 byte if assigned to a variable, so dont ask me why I was thinking that).

    I really should read the replies and the code more thoroughly or else it'll take forever for me to naturally understand concepts.
    Last edited by Dae; 07-04-2005 at 03:31 AM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with lesson 10 (File I/O)
    By sirconnorstack in forum C++ Programming
    Replies: 2
    Last Post: 05-28-2008, 05:20 PM
  2. trouble with file i/o program.
    By Pyroteh in forum C++ Programming
    Replies: 7
    Last Post: 01-09-2007, 10:29 PM
  3. Having file i/o trouble
    By LiKWiD in forum C++ Programming
    Replies: 1
    Last Post: 07-28-2004, 05:20 AM
  4. Replies: 4
    Last Post: 03-02-2003, 09:12 AM
  5. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 05:14 PM