Click to See Complete Forum and Search --> : How do you convert an object into a string in c+


japanesegirl1
03-24-2007, 10:46 PM
How do you convert an object into a string in c+

bradgrafelman
03-25-2007, 12:00 AM
I've moved this to the Echo Lounge because this is a PHP (and friends) board... not c+.

laserlight
03-25-2007, 02:52 AM
hmm... never heard of c+. Did you mean C++?

MarkR
03-25-2007, 07:30 AM
You can't convert an object into a string in the general case in C++.

If the object has an overloaded << operator for ostreams (which is common, so you can use it with cout <<), then you can use a stringstream thus:

// need to include <sstream>
// Also <string>
{
SomeClass obj; // What we want to convert...
using namespace std; // I'm lazy; ostringstream and string are in std
ostringstream oss;
oss << obj;
string str = oss.str(); // There's your string
}


Mark

dalecosp
03-26-2007, 05:16 PM
hmm... never heard of c+. Did you mean C++?
And, furthermore, how do we know you're really a Japanese Girl? :queasy:

You could really be an overweight balding 79.3 year old Yakut. :eek:

Not that it'd really matter, of course. ;)

Except Brad would have just deleted it in that case ( .... OK, OK! Just kidding, both of ya!) :D

madwormer2
03-27-2007, 04:14 PM
I actually thought she was an overweight balding old guy with an odd picture.

Sorry :)

dalecosp
03-27-2007, 10:42 PM
Well, now I'm confused. Laserlight has a pic, but the OP doesn't.

madwormer2
03-28-2007, 04:58 AM
Now I'm confused

Gonna go to college...

laserlight
03-28-2007, 12:08 PM
Dont worry, I am confused too...

dalecosp
03-28-2007, 12:26 PM
OK, here's what I know from my end to shed light.

1. I was talking to the OP, even though I quoted laserlight.
2. I know the difference between a one-shot newb poster who claims (rightly or wrongly) to be a Japanese girl and an experienced board guru who has more posts than most of the rest of us.
3. I know that Japan and Singapore and quite a ways apart. Even taking into account the farthest southern islands, definitely more than 1000 kilometres, by my best judgment without wasting time in an atlas or Google-earth.
4. I also know that use of this board to get quick answers to your homework assignments is way too common.

:glare:

:D