Hi,
Is there any way to initiate a istringstream object's string without
using constructor. I have tried the str() function but it did not work.
For example, I want to write the following code:
istreamstring iss(my_string);
then do somethings that involes the >> operator
then I want to change the string content in this buffer to other string
and use the >> operator on it again.
I have tried iss.str(my_new_string), but it does not work.Anybody knows
how to do this?
Thanks very much
Viet 3 7474
"Viet Le Hong" <lh****@iprimus.com.au> wrote Hi, Is there any way to initiate a istringstream object's string without using constructor. I have tried the str() function but it did not work. For example, I want to write the following code:
istreamstring iss(my_string);
then do somethings that involes the >> operator
then I want to change the string content in this buffer to other string and use the >> operator on it again.
I have tried iss.str(my_new_string), but it does not work.Anybody knows how to do this?
That is how you do it. It works for me. Post a complete, compilable code
sample and tell us where the error occurs.
That was the code I have written in my program, sorry I could not post
all my program because it's quite long. The next light function read new
line from a file, I have check the function and it works fine. The
problen happens after the >> call in the read eye part, it does not
change the value of "command" variable at all.
Thanks
Viet
camera res;
string command;
// read image size
next_line();
istringstream ss(buffer);
ss >> command;
if (command!="IMAGESIZE")
throw parser_error_exception("Invalid image size command when reading
camera");
else
{
int width, height;
ss >> width >> height;
res.set_image_size(width,height);
}
// read eye
next_line();
ss.str(buffer);
ss >> command;
if (command!="EYE")
throw parser_error_exception("Invalid eye command when reading camera");
else
{
double x,y,z;
ss >> x >> y >> z;
res.set_eye(x,y,z);
}
Viet Le Hong wrote: That was the code I have written in my program, sorry I could not post all my program because it's quite long. The next light function read new line from a file, I have check the function and it works fine. The problen happens after the >> call in the read eye part, it does not change the value of "command" variable at all. Thanks
What might have happened, is that the stream object is put into an
invalid state by one of the read operations. You should generally
test the state of a stream after every read. The clear () member
function is used to reset the state.
The comp.lang.c++ FAQ (Google for C++ FAQ) has a good section on IO
which is almost certain to help you get your code working.
Regards,
Buster.
Viet camera res;
string command; // read image size next_line(); istringstream ss(buffer); ss >> command; if (command!="IMAGESIZE") throw parser_error_exception("Invalid image size command when reading camera"); else { int width, height; ss >> width >> height; res.set_image_size(width,height); }
// read eye next_line(); ss.str(buffer); ss >> command; if (command!="EYE") throw parser_error_exception("Invalid eye command when reading camera"); else { double x,y,z; ss >> x >> y >> z; res.set_eye(x,y,z); } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Samuele Armondi |
last post by:
Hi everyone,
Since istringstream objects are not assignable, I'm using the following code
to allocate some dynamically. My question is: Is this the correct way of
doing it? Am I deleting all the...
|
by: Agent Mulder |
last post by:
I try to remove the spaces from a string
using an old trick that involves an
istringstream object. I expect the while-condition
while(istringstream>>string) to evaluate to
false once the...
|
by: bml |
last post by:
Could you help and answer my questions of istringstream? Thanks a lot!
1. Reuse an "istringstream"
istringstream ist;
ist.str("This is FIRST test string");
ist.str("This is SECOND test...
|
by: Donald Canton |
last post by:
Hi,
I'm using Bjarne's book to learn C++ and am stuck on the Calc program
in Section 6. Everything works fine except when I try to use
istringstream to parse a token from the command line. I...
|
by: Luther Baker |
last post by:
Hi,
My question is regarding std::istringstream. I am serializing data to
an ostringstream and the resulting buffer turns out just fine.
But, when I try the reverse, when the istringstream...
|
by: dinks |
last post by:
Hi I'm really new to c++ so please forgive me if this is really basic
but im stuck... I am trying to make a data class that uses
istringstram and overloaded << and >> operators to input and output...
|
by: JustSomeGuy |
last post by:
I am passing an istringstream to a function. I want that function to
get a copy of the istringstream and not a refrence to it.
ie when the function returns I want the istringstream to be...
|
by: Randy Yates |
last post by:
Why does this:
string AWord(string& line)
{
return line;
}
bool MYOBJECT::MyFunction(string &line)
{
int day;
|
by: James Aguilar |
last post by:
Hello all,
I am trying to use an istringstream to do some input off of cin by lines.
The following snippet does not work:
char buf;
cin.getline(buf, 90);
istringstream line1(string(buf));
|
by: icanoop |
last post by:
I would like to do this
MyClass x;
istringstream("XXX") >> x; // Works in VC++ but not GCC
instead of
MyClass x;
istringstream iss("XXX");
iss >> x; // Works in both GCC and VC++
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |