Link to home
Start Free TrialLog in
Avatar of tommym121
tommym121Flag for Canada

asked on

Clear stringStream before use

When I try to use hexify multiple time, it seems to hexify the input twice.  I believe I need to clear stringstream everytime when I use it. But how? Can anyone help me?

int main() {

	string s = "My error message\n My error message\n My error message\n My error message";
	stringstream ss;

	cout << for_each(s.begin(), s.end(), hexify<char>(ss)) << endl;
	cout << for_each(s.begin(), s.end(), hexify<char>(ss)) << endl;
	// Or, as in your case:
	//
	// log4cpp::Category::getRoot() <<  log4cpp::Priority::DEBUG << for_each(s.begin(), s.end(), hexify<char>(ss)) << endl;

	return 0;
}

Open in new window

SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tommym121

ASKER

JKR,

How can we initialize ss with out like hexify(stringstream& out) : ss(out), .....
And then clear the string. How can that work>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
JKR.

Is it right ss(out) like calling fopen?  However stringstream::str() really adjust what in the pipeline, in this case, it is string stream.  Is this the right way to look at it. That is why you can initialize, before clean up the pipeline.
Sorry, but either me or you got a bit confused here.. how would 'fopen()' enter the stage?
JKR,

I am sure I am the confused one and I got you confuse.  I mean ss(out) like simply attach 'out' to SS but does not copy 'out' content into ss:str().

Or maybe I should let you explain.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks