This is what I want to do with the line:
fullmsg += ": " + GetLastError();
fullmsg is a string object. I'm trying to concatenated GetLastError(),
which is type int, to the string. Would an integer be printed or a
character with the code that is equal to GetLastError() that would be
printed?
Thanks in advance.
|
|
0
|
|
|
|
Reply
|
stanigator (149)
|
8/14/2008 7:31:01 PM |
|
ssylee wrote:
> This is what I want to do with the line:
>
> fullmsg += ": " + GetLastError();
>
> fullmsg is a string object. I'm trying to concatenated GetLastError(),
> which is type int, to the string. Would an integer be printed or a
> character with the code that is equal to GetLastError() that would be
> printed?
No, this wouldn't work as you expected (it shouldn't even compile).
You probably want to do
std::ostringstream os;
os << ": " << GetLastError();
fullmsg += os.str();
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
|
|
0
|
|
|
|
Reply
|
v.Abazarov (13255)
|
8/14/2008 8:21:56 PM
|
|
On 14 ao=FBt, 22:21, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> You probably want to do
>
> =A0 =A0 std::ostringstream os;
> =A0 =A0 os << ": " << GetLastError();
> =A0 =A0 fullmsg +=3D os.str();
It's certainly what he would like to do, yep.
To the author (ssylee) > you can't concatenate that simply strings
with integers. You first have to create an ostringstream, then put the
integers, chars and anything else you want in it, using the <<
operator. Then os.str() returns the finally built string and clears
the ostringstream's buffer.
|
|
0
|
|
|
|
Reply
|
alpmestan (6)
|
8/14/2008 9:13:22 PM
|
|
On Aug 14, 2:13=A0pm, Alp Mestan <alpmes...@gmail.com> wrote:
> On 14 ao=FBt, 22:21, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
>
> > You probably want to do
>
> > =A0 =A0 std::ostringstream os;
> > =A0 =A0 os << ": " << GetLastError();
> > =A0 =A0 fullmsg +=3D os.str();
>
> It's certainly what he would like to do, yep.
>
> To the author (ssylee) > you can't concatenate that simply strings
> with integers. You first have to create an ostringstream, then put the
> integers, chars and anything else you want in it, using the <<
> operator. Then os.str() returns the finally built string and clears
> the ostringstream's buffer.
Thank you for your replies. I guess I was trying to hard to make up a
shortcut like that. But I've managed to find another method to achieve
what I initially wanted to do when I've made the first post.
|
|
0
|
|
|
|
Reply
|
stanigator (149)
|
8/14/2008 10:08:50 PM
|
|
On Aug 15, 12:08 am, ssylee <staniga...@gmail.com> wrote:
> On Aug 14, 2:13 pm, Alp Mestan <alpmes...@gmail.com> wrote:
> > On 14 ao=FBt, 22:21, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> > > You probably want to do
> > > std::ostringstream os;
> > > os << ": " << GetLastError();
> > > fullmsg +=3D os.str();
> > It's certainly what he would like to do, yep.
> > To the author (ssylee) > you can't concatenate that simply
> > strings with integers. You first have to create an
> > ostringstream, then put the integers, chars and anything
> > else you want in it, using the << operator. Then os.str()
> > returns the finally built string and clears the
> > ostringstream's buffer.
> Thank you for your replies. I guess I was trying to hard to
> make up a shortcut like that. But I've managed to find another
> method to achieve what I initially wanted to do when I've made
> the first post.
Typically, you'll have a function somewhere along the lines of:
std::string
getSystemErrorMessage(
SystemErrorCodeType errorCode )
{
LPVOID msgBuf ;
FormatMessage(
( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS ),
NULL,
errorCode,
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &msgBuf,
0,
NULL ) ;
std::string result( static_cast< char const*
>( msgBuf ) ) ;
LocalFree( msgBuf ) ;
return result ;
}
(with a corresponding version for Unix, of course). And since
it returns a string, you can easily concatenate its results.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
|
|
0
|
|
|
|
Reply
|
james.kanze (9594)
|
8/15/2008 8:32:52 AM
|
|
On Fri, 15 Aug 2008 01:32:52 -0700 (PDT), James Kanze rote:
>Typically, you'll have a function somewhere along the lines of:
> std::string getSystemErrorMessage(SystemErrorCodeType errorCode)
> {
> LPVOID msgBuf ;
> FormatMessage(
> ( FORMAT_MESSAGE_ALLOCATE_BUFFER
> | FORMAT_MESSAGE_FROM_SYSTEM
> | FORMAT_MESSAGE_IGNORE_INSERTS ),
> NULL,
> errorCode,
> MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT),
> (LPTSTR) &msgBuf,
> 0,
> NULL ) ;
> std::string result( static_cast< char const*(msgBuf));
> LocalFree( msgBuf ) ;
> return result ;
> }
>
>(with a corresponding version for Unix, of course). And since
>it returns a string, you can easily concatenate its results.
By converting the code from C to C++ it lost exception safety. (Ok,
that's just nitpicking since out-of-memory isn't really an exception
but a fatal error). The return value of FormatMessage should be
checked, though.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
|
|
0
|
|
|
|
Reply
|
rpbg123 (870)
|
8/16/2008 4:35:24 PM
|
|
|
5 Replies
34 Views
(page loaded in 0.071 seconds)
Similiar Articles: shared_ptr as map key - comp.lang.c++.moderatedmap<shared_ptr<const string>,int> xxx; shared_ptr<string> foo (new string("hello ... To write std::map via ostream_iterator, it's necessary ... like class that is able ... Some text processing questions - comp.lang.vhdl... sense ("const ref") but can't be done; function parameters must be of class ... not standard, most simulators probably provide some form of C-like string manipulation ... comp.lang.python - page 2... variable can be an internal variable in a class. ... convenient function that can readily convert a string ... ast manipulation 2 70 (11/17/2009 2:55:03 PM) Hello, I am ... pkginfo -l doesnt work - comp.unix.solarisSome programmers are better with string manipulation tools than others. ... Solaris Packages The Class Action Scripts work similarly during removal of a ... FTGL font engine - comp.graphics.api.opengl... service) for loading a font file then using the FTGL Render class method to display the string. ... To me, it seems FreeType2 and FTGL do not allow any manipulation of the ... Adding simple database, excel export, and reports with D4 Pro ...I use the first 15 characters of each string as an ID ... Dialogs, StdCtrls; type TForm1 = class(TForm ... used a separate program to do the database manipulation ... numeric_limits<>::max() - comp.lang.c++... been implemented as a private object for easier, safer and more efficient manipulation ... point values could not be const static members initialized in the class ... How tu use multivalent pdf tools - comp.text.pdf... which is the second argument to java, that string ... PDF structure manipulation tools - comp.text.pdf... simple ... of PDF syntax says? If you use the PRTokeniser class ... processing output of external command - comp.lang.awk4) You want to do some manipulation on that list of details to produce your final output. ... Capturing the output from a system command into a single string ... processing ... Speed-up the reading of large binary files with complex structures ...If a specific string appears repeatedly in an M-file ... I'm not suggest any low level manipulation, but ... (e.g., using something like your pointer class and then ... String ManipulationThe String class of the .NET framework provides many built-in methods to facilitate the comparison and manipulation of strings. It is now a trivial matter to get data ... Java Tutorial 7 - String Manipulation - Cogeco - Television ...NOTE: For the following parameters the prefix g indicates string, i indicates integer and c indicates character types. The String Class. String class objects work ... 7/12/2012 12:44:53 PM
|