Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7885451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:04:28+00:00 2026-06-03T05:04:28+00:00

I have a input stream IPCimstream, which returns a pointer to the character buffer

  • 0

I have a input stream IPCimstream, which returns a pointer to the character buffer of its stream with dataBuf() function.

Say I have
IPCimstream ims;

What is the difference between printing
1.

cout << ims.dataBuf() << endl;   

and
2.

cout << (void*)ims.dataBuf() << endl;

If possible pls explain with an example. Say ims.dataBuf() has “Hello world\n”, etc. or other examples which you feel explain the difference well. Sorry I am new to input stream and I couldnt come up with more interesting examples if there might be any.

Also, what would be the difference if IPCimstream is a character stream vs. binary stream. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:04:30+00:00Added an answer on June 3, 2026 at 5:04 am

    Well, the difference is that char* overload of cout::operator<< treats the pointer as a zero-terminated C string (well, C strings are just char pointers anyway), so it outputs the string itself. If your buffer is not a zero-terminated string, the cout‘s guess is wrong, so it will output some random garbage till the first \0.

    The void* version of the same operator doesn’t know what is the object behind the pointer, so everything it can do is just to output the pointer value.

    You see, this behaviour is not connected with the IPCimstream class, it’s just how cout works. (Look at teh example at http://ideone.com/1ErtV).

    Edit:
    In the case if dataBuf containing "Hello world\n" the char* version interprets the pointer as a zero-terminated string. So it will output the characters “Hello world”, output the newline character, and than all the characters that happen to be in the memory after \n till the next \0. If there is no such character in the memory, the program may just crash. (For language purists: you’ll get undefined behaviour.)

    The void* version doesn’t know how to treat the value pointed to by the pointer — so it outputs the pointer value (i.e., the address) itself.

    Edit 2:
    The difference between the character stream and binary stream may be only in the data they hold. In any case, if dataBuf() returns a char*, the cout will output all the characters found in the buffer (and potentially beyond it) until the first \0 (or just nothing if \0 is at the beginning), and with the cast you’ll get just the buffer’s address output as string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input stream coming form a blackbox (say B). All the messages
I'm having an issue reading from a java input stream. I have a buffer
I have an input stream which is being converted to XML, and read. When
I have an input stream, and I want to map to output lines. For
I have been testing the performance of reading server socket input stream. I found
So a FILE stream can have both input and output buffers. You can adjust
I have input fields, which I process with AJAX and send it on another
I have an input stream from a binary file. I want to create a
I have a frame of 22 bytes. The frame is the input stream from
I have in an input stream the complete source code of a class. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.