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 


[Question] Converting hex/dec values with C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Thu Dec 18, 2008 1:38 pm    Post subject: [Question] Converting hex/dec values with C++ Reply with quote

Hey guys,
I'm learning C++ with the help of "Learning C++" book by Tom Swan but using Miscrosof Visual C++ as a compiler instead of the Zortech one which came with the book..
I tired compiling this code but got an error (C2664 - cannot convert parameter 1 from 'long' to 'class ios &' A reference that is not to 'const' cannot be bound to a non-lvalue).
What am I doing wrong? o.O

Code:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>

void main()
{
   long value;
   char s[80];      

   cout<<"Value?";
   cout<<'\n';
   cin>>s;
   value = atol(s);
   cout<<"Decimal ="      <<dec(value)
      <<"Hexadecimal ="   <<hex(value)
      <<"Octal ="         <<oct(value)<<'\n';
}


EDIT: The error is regarding the last 3 lines..

_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++


Last edited by Kipodimkozim on Thu Dec 18, 2008 4:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Thu Dec 18, 2008 1:46 pm    Post subject: Reply with quote

What line was the error on? We need to see the code for dec, hex, oct.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Thu Dec 18, 2008 2:11 pm    Post subject: Reply with quote

Problems:
*using dec, hex, and oct wrong
*forgetting to append std:: or using
*Visual c++ doesn't take iostream.h, just iostream

Code:

#include <iostream>
#include <stdlib.h>

int main(void)
{
   long value;
   char s[80] = { 0 };

   std::cout << "Value?\n";
   std::cin >> s;

   value = atol(s);
   std::cout << "Decimal = " << value << std::endl;
   std::cout << "Hexadecimal = "<< std::hex << value << std::endl;
   std::cout << "Octal = " << std::oct << value << std::endl;

   return 0;
}
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Thu Dec 18, 2008 2:36 pm    Post subject: Reply with quote

Cool tnx. I didnt know windows had these functions ( i/o library) !
Back to top
View user's profile Send private message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Thu Dec 18, 2008 4:29 pm    Post subject: Reply with quote

killersamurai wrote:
Problems:
*using dec, hex, and oct wrong
*forgetting to append std:: or using
*Visual c++ doesn't take iostream.h, just iostream

Code:

#include <iostream>
#include <stdlib.h>

int main(void)
{
   long value;
   char s[80] = { 0 };

   std::cout << "Value?\n";
   std::cin >> s;

   value = atol(s);
   std::cout << "Decimal = " << value << std::endl;
   std::cout << "Hexadecimal = "<< std::hex << value << std::endl;
   std::cout << "Octal = " << std::oct << value << std::endl;

   return 0;
}


What's wrong with the oct, hex and dex? I'm using an older version of the book and he wrote the code the same way I did and it worked for him..

EDIT: I tried compiling it the way you wrote it and now I get - error C2653: 'std' : is not a class or namespace name (10 errors for each time std shows in the code).

nog_lorp wrote:
What line was the error on? We need to see the code for dec, hex, oct.


What do u mean the code? at the book I'm learning from he compiled that cxact code with adding anything (with zortech comipler tho).

_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++


Last edited by Kipodimkozim on Thu Dec 18, 2008 4:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Thu Dec 18, 2008 4:37 pm    Post subject: Reply with quote

cuz u forgot to include use namespace std
_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Back to top
View user's profile Send private message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Thu Dec 18, 2008 4:54 pm    Post subject: Reply with quote

Bizarro wrote:
cuz u forgot to include use namespace std


Will I have to write 10 different names for each std (namespace first, second and such..) or will writting "using namespace std;" at the begining be enough?

Ugh I hate that stupid book I should've bought a different one..

_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Thu Dec 18, 2008 5:02 pm    Post subject: Reply with quote

Kipodimkozim wrote:
Bizarro wrote:
cuz u forgot to include use namespace std


Will I have to write 10 different names for each std (namespace first, second and such..) or will writting "using namespace std;" at the begining be enough?

Ugh I hate that stupid book I should've bought a different one..

That's enough, what it does is basically cuts out the STANDARD:: (std::) out of the keywords.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
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