NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Tue Apr 19, 2011 1:23 pm Post subject: std::string problems |
|
|
Hello,
I've got a problem with the std::string library.
I've got a WORD variables which get his value by the game. The value of it is a header of a packet, something like 13 10, always 4 numbers. I guess they are 1010 inside the WORD.
But I used in C this
Code: | StringCchPrintf(szCommand, 4 + 1, TEXT("%04X"), pSend->lpPacket->EMSStruct->Command); |
But now I'm trying to do this in C++, I tried two things, the boost library and the stringstream method.
(WORD value is inside a struct, that works fine )
Boost:
Code: | sHeader =lexical_cast<std::string>(SendStruct->lpPacket->EMSStruct->Command); |
stringstream
Code: | std::ostringstream oss;
oss<<std::hex<<(SendStruct->lpPacket->EMSStruct->Command); |
With the boost method the only thing what I get is 1 number, example A instead of AA 10. If someone knows a good solution to this in C++ I would be thankfull.
Another thing is when I use the boost library ofc it will not be in hex but in dec, so stringstream is the best way to make the string in hex? If so is it usefull to use the boost function?
thanks,
NM
|
|
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Tue Apr 19, 2011 5:36 pm Post subject: |
|
|
Code: | #include <Windows.h>
#include <iostream>
#include <sstream>
int main( int, char* [] )
{
WORD wdHeader = 0xAA10; // Assuming this is what you meant.
std::stringstream oss;
oss << std::hex << std::uppercase << wdHeader;
std::cout << oss.str();
return 0;
} |
Works fine for me, prints out:
AA10
_________________
- Retired. |
|