473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

istringstream and redefining the stream inside a for loop

13
I'm trying to figure out how to convert an array of type "string" into integers, and I have begun using istringstream.

I made a program to test how istringstream works, and I've been having trouble updating the characters in the stream within a for loop.

Here's a code snippet:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     string some_string="15372";
  3.     int a;
  4.     istringstream buffer(some_string);
  5.     for (int n=0;n<5;n++){
  6.         cout<<n<<endl;
  7.         some_string=some_string+"923";
  8.         buffer.str(some_string);
  9.         buffer>>a;
  10.         cout<<a<<endl<<some_string<<endl;
  11.         } 
some_string keeps getting larger, however the buffer variable remains the same

instead of changing as some_string does.

Essentially, I'm looking for a way to update buffer after some_string changes.
Jan 25 '08 #1
2 2150
RRick
463 Expert 256MB
I had a similar problem where I couldn't change the contents of an istringstream. For gnu C++, I found the following will reset the contents of istringstream to a new value.

Expand|Select|Wrap|Line Numbers
  1. istringstream iss( "stuff');
  2. iss.clear();  iss.set( "replace with this");
  3. .....
Jan 25 '08 #2
rolan
13
unfortunately, I'm unable to use that compiler, my prof wants to be able to compile it on his machine to test it using the Dev-C++ IDE and compiler.
Jan 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
1
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...
7
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...
4
by: Brandon | last post by:
I'm using an istringstream to convert some integers stored in string form to integers. However, each integer is stored in a differnt string. So, I used istringstream's str(string) method for the...
4
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...
7
by: ma740988 | last post by:
The string object value_f doesn't produce the right output. At issue, - I suspect - is the conversion from string to int with istringstream. An alternate approach? Thanks in advance #include...
6
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...
1
by: Adam Parkin | last post by:
Hello all, I'm trying to write a function which given a std::string parses the string by breaking the sentance up by whitespace (\t, ' ', \n) and returns the result as a vector of strings. Here's...
11
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++
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.