473,383 Members | 1,863 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,383 software developers and data experts.

How to shrink a stringstream

Given a stringstream object (tokens) containing
tokens << "token1 token2 token3 token4"

I'd like to extract the first token, which I do by saying

tokens >> token ; // where token is a string

And then pass the remaining portion down to a function.
If I just pass the tokens (even after removing one item from it)
to my function, I see that the entire payload is passed down.

How do I pass the remaining portion down to a function ?
ie "token2 token3 token4"

Thanks
Jul 19 '05 #1
2 4009

"Medi Montaseri" <mo*******@netscape.net> wrote in message
news:c9**************************@posting.google.c om...
Given a stringstream object (tokens) containing
tokens << "token1 token2 token3 token4"

I'd like to extract the first token, which I do by saying

tokens >> token ; // where token is a string

And then pass the remaining portion down to a function.
If I just pass the tokens (even after removing one item from it)
to my function, I see that the entire payload is passed down.

How do I pass the remaining portion down to a function ?
ie "token2 token3 token4"


It would be better if you posted *compilable* code,
so we know for sure what's wrong.

Example:

#include <iostream>
#include <sstream>

void foo(std::stringstream& ss)
{
std::string tok;

while(ss >> tok)
std::cout << tok << '\n';
}

int main()
{
std::stringstream tokens("token1 token2 token3 token4");
std::string token;
tokens >> token;
foo(tokens);
return 0;

}

Output:

token2
token3
token4

HTH,
-Mike
Jul 19 '05 #2
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<Zm*****************@newsread4.news.pas.earth link.net>...
"Medi Montaseri" <mo*******@netscape.net> wrote in message
news:c9**************************@posting.google.c om...
Given a stringstream object (tokens) containing
tokens << "token1 token2 token3 token4"

I'd like to extract the first token, which I do by saying

tokens >> token ; // where token is a string

And then pass the remaining portion down to a function.
If I just pass the tokens (even after removing one item from it)
to my function, I see that the entire payload is passed down.

How do I pass the remaining portion down to a function ?
ie "token2 token3 token4"


It would be better if you posted *compilable* code,
so we know for sure what's wrong.

Example:

#include <iostream>
#include <sstream>

void foo(std::stringstream& ss)
{
std::string tok;

while(ss >> tok)
std::cout << tok << '\n';
}

int main()
{
std::stringstream tokens("token1 token2 token3 token4");
std::string token;
tokens >> token;
foo(tokens);
return 0;

}

Output:

token2
token3
token4

HTH,
-Mike

I must have been sleepy (or even sleeping) last night....you are 100% correct...
it works as expected....sorry for the false alarm....
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill Beacom | last post by:
Hi all, I am trying to use stringstream to assemble a text message from a set of user-defined objects that have the insertion operator overloaded. It seems to be putting them into the...
2
by: Woodster | last post by:
I am using std::stringstream to format a string. How can I clear the stringstream variable I am using to "re use" the same variable? Eg: Using std::string std::string buffer; buffer =...
1
by: R Camarda | last post by:
Help, I have a database that has a data file of 2GB and a log file of 31GB. In enterprise manager, when I choose shrink it says there is 30GB of unused space. When I shrink the database, it does...
5
by: BashiraInTrouble | last post by:
Hi Friends, I have tried almost everything but I cant seem to shrink the transaction log. Executing DBCC SQLPERF(LOGSPACE) gives me this info: Database Log Size (MB) Log Space Used (%) ...
3
by: Mike Chirico | last post by:
Sorry about the newbie question. What's the best way to convert numbers to strings in C++. The following works, but is it better than using the sprintf() "old C" way of converting? #include...
1
by: KidLogik | last post by:
Hello! I am using std::stringstream && std::string to parse a text file -> std::ifstream in; std::string s; std::streamstring ss; int n; I grab each line like so -> std::getline(in,s);
5
by: cherico | last post by:
I'd like to read stings from cin and put them in stringstream. I use a string object as an intermediate "container" to store data from cin and then put them in stringstream. stringstream ss ;...
5
by: William Payne | last post by:
How do you get rid the contents in a std::stringstream? I'm using one in a for loop to format some status messages which I print to the screen. The stringstream member function clear() only clears...
6
by: Major Drake | last post by:
Windows 2003 64 bit sp2 + SQL Server std 32 bit sp2 compability mode 90, recovery model simple. I have about 40 Gb database where is about 98% free space (I deleted data from tables). dbcc...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
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
0
BarryA
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...
0
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 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.