Is there such a thing in C++ as stream which you can pass data into
and then retrieve data out of on the other end (without interacting
with the user or a file)?
For example, I'd like to extract a bunch of numbers, separated by
whitespace from a string ... say for example:
mystring = "100 2.0 666 3.14";
I realize that if the string contained only one number, I could use
atoi(). If it was reading in from a file, I could use myfilestream >>
a >> b >> c >> d;.
So basically I'm wondering if there's such a thing as a type of stream
object such that I could feed such a string into on one end and then
extract the variables out of the other end.
Like this:
stream mystream;
mystream << mystring;
mystream >> a >> b >> c >> d;
I know I could achieve this by streaming it out to a file and then
streaming it back in; I just want to know if there's a way to skip the
middle stage.
-Keith 4 2086
In article <fe********************************@4ax.com>, sp@m.me says... Is there such a thing in C++ as stream which you can pass data into and then retrieve data out of on the other end (without interacting with the user or a file)?
From your description, you want to look up std::stringstream.
--
Later,
Jerry.
The universe is a figment of its own imagination.
Poldanziern <sp@m.me> wrote in news:fepeovcjgo8lg5cr2tl2k6n7qd95qiav99@
4ax.com: Is there such a thing in C++ as stream which you can pass data into and then retrieve data out of on the other end (without interacting with the user or a file)?
For example, I'd like to extract a bunch of numbers, separated by whitespace from a string ... say for example:
mystring = "100 2.0 666 3.14";
I realize that if the string contained only one number, I could use atoi(). If it was reading in from a file, I could use myfilestream >> a >> b >> c >> d;.
So basically I'm wondering if there's such a thing as a type of stream object such that I could feed such a string into on one end and then extract the variables out of the other end.
Like this:
stream mystream; mystream << mystring; mystream >> a >> b >> c >> d;
I know I could achieve this by streaming it out to a file and then streaming it back in; I just want to know if there's a way to skip the middle stage.
Close....
#include <sstream>
#include <string>
std::string mystring = "100 2.0 666 3.14";
std::istringstream mystream(mystring.c_str());
mystream >> a >> b >> c >> d;
(OK... assuming that a-d are appropriately typed....)
On Sat, 11 Oct 2003 02:39:35 GMT, Jerry Coffin <jc*****@taeus.com>
wrote: In article <fe********************************@4ax.com>, sp@m.me says... Is there such a thing in C++ as stream which you can pass data into and then retrieve data out of on the other end (without interacting with the user or a file)?
From your description, you want to look up std::stringstream.
From a preliminary Google search, I believe that is exactly what I was
looking for. Thanks!
-Keith
Andre Kostur wrote: Poldanziern <sp@m.me> wrote in news:fepeovcjgo8lg5cr2tl2k6n7qd95qiav99@ 4ax.com:
Is there such a thing in C++ as stream which you can pass data into and then retrieve data out of on the other end (without interacting with the user or a file)?
For example, I'd like to extract a bunch of numbers, separated by whitespace from a string ... say for example:
mystring = "100 2.0 666 3.14";
I realize that if the string contained only one number, I could use atoi(). If it was reading in from a file, I could use myfilestream >> a >> b >> c >> d;. So basically I'm wondering if there's such a thing as a type of stream object such that I could feed such a string into on one end and then extract the variables out of the other end.
Like this:
stream mystream; mystream << mystring; mystream >> a >> b >> c >> d;
I know I could achieve this by streaming it out to a file and then streaming it back in; I just want to know if there's a way to skip the middle stage.
Close....
#include <sstream> #include <string>
std::string mystring = "100 2.0 666 3.14"; std::istringstream mystream(mystring.c_str());
That constructor wants a string, not a pointer to char.
mystream >> a >> b >> c >> d;
(OK... assuming that a-d are appropriately typed....) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: googlegroups |
last post by:
I am playing with the XMLHTTPRequest method to perform client/server
transactions. I have it set up right now so that when readyState is 4,
it takes the XML and processes it. This works great until...
|
by: John |
last post by:
Hi all,
I have an (well, what I think to be, at least) interesting question:
Is it possible to stream data down to the client and, after a certain amount
of data has been streamed, allow the...
|
by: A.M-SG |
last post by:
Hi,
I have a ASP.NET aspx file that needs to pass large images from a network
storage to client browser. The requirement is that users cannot have access
to the network share. The aspx file...
|
by: mpaliath |
last post by:
Hi guys
I am currently involved in a project which requires me to recieve and
play streaming video as well as send it. In Visual C++ is there any
free library which helps me do this as...
|
by: Amjad |
last post by:
Hi i am writing a application where i want to browse video file and copy data
into stream and send that stream over network...I have develop P2P windows
application where i successfully transfer...
|
by: SPG |
last post by:
Hi,
Two questions for you all..
Firstly, is there a way of streaming video using PHP? At the moment I just
have a link to a video file and the whole thing downloads before playing
which is a...
|
by: Tony K |
last post by:
Is streaming audio capable in asp.net 2.0 / AJAX? What I mean by streaming
audio is: ability to play one or more songs back to back...or maybe even let
the user select several songs to play and it...
|
by: pmakoi |
last post by:
dear all
this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic
I am...
|
by: Faisal Shafiq |
last post by:
I want to upload a file direct to the Silverlight Streaming Service from a
Web Client such as silverlight application.
As per our product requirement we want to upload a .WMV file directly from...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |