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 


C++ hex problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Fri Dec 18, 2009 6:23 am    Post subject: C++ hex problem Reply with quote

okay so ive got a nice little C++ console app, cin cout and all that

and what im trying to do basically is have the user input a hex values like 0x00001122 or just 00001122 using cin and have a dword store that value so it can be used to read some memory, however it does not work as it is, it seems to give a decimal value which makes the program crash when it tries to use it

any ideas? im well stuck

_________________
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Dec 18, 2009 10:34 am    Post subject: Reply with quote

I don't know how you are using cin, but I think you should be able to do something like:
Code:
cin >> hex >> variable;

I don't know how it would work with other cin methods like cin.get()
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Dec 18, 2009 5:22 pm    Post subject: Reply with quote

the std::hex manipulator works on input as well.

set it back to std::dec if you need it back to normal.
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Fri Dec 18, 2009 8:51 pm    Post subject: Reply with quote

thanks for the help btw

ive been trying that too, heres the code


Code:
DWORD Add, Off, Value;

      cout << "Enter address: ";
      cin >> hex >> Add;
      
      cout << "Enter offset: ";
      cin >> hex >> Off;

      cout << "Reading address " << Add << " at offset " << Off << " ..." << endl;


and when i tried 000011bc and 1b3, it says reading at address 4540 at offset 435



hmmm, i tried using hex on the output aswell, it gives me the right number, but without the leading zeros, so 11bc instead of 000011bc, does that mean i could just add those zero to the front and it would work?

_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Dec 18, 2009 9:00 pm    Post subject: Reply with quote

setfill()
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Dec 18, 2009 9:02 pm    Post subject: Reply with quote

You could just use printf (or if you plan on having UNICODE support: _tprintf) and just set it as a pointer format flag.

Code:
_tprintf(_T("Reading address: 0x%p at offset 0x%p"), Add, Off);

_________________
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Dec 18, 2009 9:04 pm    Post subject: Reply with quote

Snootae wrote:
... it gives me the right number, but without the leading zeros, so 11bc instead of 000011bc, does that mean i could just add those zero to the front and it would work?

Slugsnack wrote:
setfill()

Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Fri Dec 18, 2009 9:04 pm    Post subject: Reply with quote

ah, thank you guys

so just filling up the zeros should work?

i shall do that

_________________
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Dec 18, 2009 9:13 pm    Post subject: Reply with quote

Fibonacci is rolling in his grave right about now.
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Fri Dec 18, 2009 9:18 pm    Post subject: Reply with quote

im sure he doesnt have a grave, or anything left by now



on a related note im still failing at getting a stupid dword with the value

_________________
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Dec 18, 2009 9:29 pm    Post subject: Reply with quote

Here is a little exercise for you.

Which number is 10?
  1. 000000000010.000000000000000
  2. 010
  3. 00000000000000000000000000000000000000000010
  4. 10
  5. All of the above.


(Yes, I'm aware if you prefix a number with 0 it is thought of as an octal... in programming. This is purely math.)
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Fri Dec 18, 2009 9:38 pm    Post subject: Reply with quote

ooooooh, d, no wait, e, no wait, e and d
_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Dec 18, 2009 9:55 pm    Post subject: Reply with quote

Code:
#include <windows.h>
#include <iomanip>
#include <iostream>
  using namespace std;

int main()
{
  DWORD Add, Off;

  cout << "Enter address: ";
  cin >> hex >> Add;
       
  cout << "Enter offset: ";
  cin >> hex >> Off;

  cout << "Reading address " << hex << setfill('0') << setw(8) << Add;
  cout << " at offset " << hex << setfill('0') << setw(8) << Off << " ..." << endl;

  return 0;
}


Despite Flyte having been given tens of thousands of dollars in scholarship money, numerous awards, and even attending a university that essentially pays him to go there, he is still full of shit. He has no interest in helping people, only showing off what little he knows.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Dec 18, 2009 10:08 pm    Post subject: Reply with quote

Slugsnack wrote:
Despite Flyte having been given tens of thousands of dollars in scholarship money, numerous awards, and even attending a university that essentially pays him to go there, he is still full of shit. He has no interest in helping people, only showing off what little he knows.


I'd argue that showing him that leading 0s do not matter, however imparted, is far more valuable than providing an answer to question he never asked. Though I'm sure you didn't realize that, since you clearly lack reading comprehension.
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Fri Dec 18, 2009 10:38 pm    Post subject: Reply with quote

im sure its your job to impart wisdom eh?
not just help with what im actually asking

thanks slugsnack

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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