Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


std::string problems

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Tue Apr 19, 2011 1:23 pm    Post subject: std::string problems Reply with quote

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
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Tue Apr 19, 2011 5:36 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites