Board index » cppbuilder » std::string question

std::string question


2004-08-18 12:27:05 AM
cppbuilder100
Instead of having something like
std::string Message;
Message = "Line: ";
Message += itoa(__LINE__, buff, 10);
Message += " File: ";
Message += __FILE__;
Message += "\n\0";
How can I add them alltogether without the need for loads of statments, which looks ugly, as when I try adding them I get messages like cannot add two pointers etc..
Thanks,
MwnN
 
 

Re:std::string question

"MwnN" < XXXX@XXXXX.COM >wrote in message
Quote
How can I add them alltogether without
the need for loads of statments
Use a formatting function such as sprintf(), ie:
char buf[300];
sprintf(buf, "Line: %d File: %s\n", __LINE__, __FILE__);
std::string Message = buf;
Gambit
 

Re:std::string question

On 17 Aug 2004 09:27:05 -0700, MwnN wrote:
Quote
How can I add them alltogether without the need for loads of statments, which looks ugly, as when I try adding them I get messages like cannot add two pointers etc..
there's always std::stringstream, and of course the boost:::lexical_cast
www.boost.org/libs/conversion/lexical_cast.htm
--
good luck,
liz
 

{smallsort}

Re:std::string question

"Liz Albin" < XXXX@XXXXX.COM >wrote in message news:16yopfbokeus$.1c148403iwo6i$ XXXX@XXXXX.COM ...
Quote
On 17 Aug 2004 09:27:05 -0700, MwnN wrote:

>How can I add them alltogether without the need for loads of statments, which looks ugly, as when I try adding them I get
messages like cannot add two pointers etc..

there's always std::stringstream, and of course the boost:::lexical_cast
www.boost.org/libs/conversion/lexical_cast.htm
And boost::format.hpp. It has "similar" syntax to the (s)printf
stuff but is safer.