The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 07:59:24 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Concatonating strings, numbers, and your cat  (Read 3536 times)
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« on: May 25, 2007, 08:22:56 AM »

In C++ it is seamingly difficult to concatonate different types easily.

Fear not the STL and m0nkeymafia are here to help

Observe stringstreams in action Cheesy
int num1 = 24;
float num2 = 7.45;
std::stringstream formatter;
formatter << "My Age Is: " << num1 << ", my penis size is: " << num2;

//you can get the string via formatter.str(), you can even get the character array via formatter.str().c_str()

You can, like mentioned in a previous post, modify the widths of numbers, and other such things.
STL FTW
Logged

I am Tyler Durden
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: May 25, 2007, 11:33:41 AM »

Streams rock, but I have a hard time grokking them. When I apply myself to looking at the mechanics and syntax of using functions for them I can make it work, but for some reason I have this huge block about them... particularly when mixing file streams and web streams and string streams and soft flowing clear blue streams... just hard to get my arms around.

Perhaps it's even the sort of "backward" notation of the example you posted - just bounces off my brain.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« Reply #2 on: May 25, 2007, 03:26:28 PM »

Yeah streams rock, anything i can helop with lemmie know perk
sorry im drunk mauhahaa 
Logged

I am Tyler Durden
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #3 on: May 25, 2007, 06:19:43 PM »

I always seem to use std::ostringstream in my code, apart from the fact that they have a different inheritance tree and ostrstream is output specific what is the difference?

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« Reply #4 on: May 26, 2007, 01:44:38 AM »

dont know diff between the two
ostringstreams rock though
there is a bug where std::stringstream implementation in vs2005 actually leaks memory slowly.
so always use ostringstream for most your string stuff.

my favourite thing is making classes and functions that output to a stream
i.e. you pass it a std::ostream & and then you can pass it a file stream, string stream, or whatever, and itll work, and be nice and sekzy yay
Logged

I am Tyler Durden
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #5 on: May 26, 2007, 02:13:44 AM »

Under dotnet I'd be using a stringbuilder object.

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!