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. 5 1303
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
On 14 août, 22:21, Victor Bazarov <v.Abaza...@comAcast.netwrote:
You probably want to do
* * std::ostringstream os;
* * os << ": " << GetLastError();
* * fullmsg += 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.
On Aug 14, 2:13*pm, Alp Mestan <alpmes...@gmail.comwrote:
On 14 août, 22:21, Victor Bazarov <v.Abaza...@comAcast.netwrote:
You probably want to do
* * std::ostringstream os;
* * os << ": " << GetLastError();
* * fullmsg += 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.
On Aug 15, 12:08 am, ssylee <staniga...@gmail.comwrote:
On Aug 14, 2:13 pm, Alp Mestan <alpmes...@gmail.comwrote:
On 14 août, 22:21, Victor Bazarov <v.Abaza...@comAcast.netwrote:
You probably want to do
std::ostringstream os;
os << ": " << GetLastError();
fullmsg += 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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stu Cazzo |
last post by:
I have the following:
String myStringArray;
String myString = "98 99 100";
I want to split up myString and put it into myStringArray.
If I use this:
myStringArray = myString.split(" ");
it...
|
by: Kevin Buffardi |
last post by:
To those experts in standard C/C++...
In past I've been quick to use the string.h library for convenience, but now
I'm working on a project where I'm trying to maximize portability so I want
to...
|
by: CoolPint |
last post by:
Is there any way I can reduce the size of internal buffer to store
characters by std::string?
After having used a string object to store large strings, the object
seems to
retain the large...
|
by: Dim |
last post by:
I found that C# has some buggy ways to process string across methods.
I have a class with on global string var and a method where i add / remove
from this string
Consider it a buffer... with some...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: WaterWalk |
last post by:
Hello, I'm currently learning string manipulation. I'm curious about
what is the favored way for string manipulation in C, expecially when
strings contain non-ASCII characters. For example, if...
|
by: Michael D. Ober |
last post by:
OK, I can't figure out a way to optimize the following VB 2005 code using
StringBuilders:
Public Const RecSize as Integer = 105
Private buffer As String
Public Sub New()
init
End Sub...
|
by: ommail |
last post by:
Hi
I wonder if regular expressions are in general sower than using
classes like String and
Char when used for validating/parsing text data?
I've done some simple test (using IsMatch()) method...
|
by: mann_mathann |
last post by:
can anyone tell me a solution:
i cannot use the features in standard c++ string classgh i included
the string.h file but still its not working.
|
by: Bob Altman |
last post by:
Hi all,
I need to allocate a buffer large enough to store a copy of a null-terminated
string that is given to me as an argument. The code that I am using looks a lot
like old ugly C code. Is...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |