C++/VB - Newby: More VC6 errors...
Asked By Blue Streak
16-Feb-08 04:49 AM
Hello,
I am trying to typecast an int and a float into a basic_string.
The help files are less than helpful. How do I accomplish this?
The trouble is I have not touched C/C++ in 10 years.
TIA...
Koenig
(1)
Newby
(1)
Ostringstream
(1)
Minds
(1)
Pigs
(1)
Libs
(1)
ACCU
(1)
RFC
(1)
Igor Tandetnik replied...
By "typecast", you probably mean you want to format a string
representation of a number.
int n;
ostringstream os;
os << n;
string s = os.str();
See also boost::lexical_cast:
http://www.boost.org/libs/conversion/lexical_cast.htm
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
David Wilkinson replied...
Blue:
You need to look at ostringstream (or basic_ostringstream).
--
David Wilkinson
Visual C++ MVP
Alex Blekhman replied...
You didn't show the code that produces the error. Nobody can read
minds here. (Note: In C++ you can't just cast between int/float
and strings.
So, probably the best approach is to get some modern C++ textbook.
ACCU site (http://accu.org) has good reviews of programming books.
HTH
Alex
Victor Bazarov replied...
Why? What for?
You don't. What makes you think you need to "typecast"? What
are you trying to accomplish?
It might be the time you need to take a book and do some studying
of the language, eh? There is no such thing as "typecast" from
int to basic_string. If you need/want to obtain the external
representation of a number, you convert it using 'ostringstream'
or 'sprintf' or other suitable mechanism... But this is just not
the right way to learn. Get "Accelerated C++" by Koenig and Moo,
and read it.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Blue Streak replied...
Blue Streak replied...
Kenneth Porter replied...
@news.datemas.de:
I'd also recommend Scott Meyer's series:
http://www.aristeia.com/books_frames.html
late than never' a reply to this question. This is - in fact - not true. The Koenig lookup (which finds methods based on their argument namespace) means more methods are found as do with namespaces because both methods are found (one in normal scope, one due to Koenig lookup), but the selection and therefore the ambiguity lies in the number of conversions needed
lang.c++.moderated. First time posters: Do this! ] I do not see why you hold Koenig responsible - no fingerprints at all. This default kicks in when you are referring to BaseIf
what Peter Viscarola characterized as a "what is the best glue for attaching wings to pigs?" when the real question should be "How can I get a message from the barn
share storage with it. In that case, moving from the string is just fine. Great minds think alike ;-) - - Dave Abrahams BoostPro Computing http: / / www.boostpro.com [ See http: / / www.gotw.ca
is that they think with their hopes or fears or wishes rather than with their minds. - - Will Durant [ See http: / / www.gotw.ca / resources / clcm.htm for info about ] [ comp.lang