Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Read memory...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 14 Topic 43688 of 48417
Post > Topic >>

Re: Read memory buffer via stream interface

by kasthurirangan.balaji@[EMAIL PROTECTED] Mar 5, 2008 at 01:38 AM

On Mar 5, 2:16=A0pm, Steven Woody <narkewo...@[EMAIL PROTECTED]
> wrote:
> Hi,
>
> for example, i have
>
> =A0 unsigned char buff[ 100 ]
>
> the buffer hold a sequences of raw bytes. =A0My question is, what is the
> standard method of reading the `buff' via std::istream interface?
>
> A relative question is: how to write to the `buff' via std::ostream
> interface? I think this can be done by using std::stringstream, but i
> am not sure of it.
>
> Thanks.
>
> -
> woody

Use std::istringstream for input, std::ostringstream for output,
std::stringstream for both. Once you have created a stringstream, you
can use istream/ostream read/write facilities on it.

#include <iostream>
#include <cstring>
#include <sstream>

main()
{
std::stringstream sstr;
sstr << "balaji";
std::cout << sstr.str() << '\n';
sstr.str(""); //clear in-memory data
char buf[100];
strcpy(buf,"asdkjabvdba");
std::stringstream sstr1(buf);
std::cout << sstr1.str() << '\n';
}

Thanks,
Balaji.
 




 14 Posts in Topic:
Read memory buffer via stream interface
Steven Woody <narkewoo  2008-03-05 01:16:26 
Re: Read memory buffer via stream interface
kasthurirangan.balaji@[EM  2008-03-05 01:38:00 
Re: Read memory buffer via stream interface
Steven Woody <narkewoo  2008-03-05 03:57:06 
Re: Read memory buffer via stream interface
Micah Cowan <micah@[EM  2008-03-05 09:05:16 
Re: Read memory buffer via stream interface
kasthurirangan.balaji@[EM  2008-03-05 05:12:34 
Re: Read memory buffer via stream interface
James Kanze <james.kan  2008-03-05 05:49:58 
Re: Read memory buffer via stream interface
kasthurirangan.balaji@[EM  2008-03-05 06:17:03 
Re: Read memory buffer via stream interface
Steven Woody <narkewoo  2008-03-05 06:27:19 
Re: Read memory buffer via stream interface
Steven Woody <narkewoo  2008-03-05 19:19:14 
Re: Read memory buffer via stream interface
kasthurirangan.balaji@[EM  2008-03-05 23:12:24 
Re: Read memory buffer via stream interface
Steven Woody <narkewoo  2008-03-06 00:12:31 
Re: Read memory buffer via stream interface
kasthurirangan.balaji@[EM  2008-03-06 02:14:53 
Re: Read memory buffer via stream interface
James Kanze <james.kan  2008-03-06 04:23:21 
Re: Read memory buffer via stream interface
kasthurirangan.balaji@[EM  2008-03-06 05:13:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:13:18 CST 2008.