| View previous topic :: View next topic |
| Author |
Message |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Thu Dec 18, 2008 1:38 pm Post subject: [Question] Converting hex/dec values with C++ |
|
|
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 |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Thu Dec 18, 2008 1:46 pm Post subject: |
|
|
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 |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Thu Dec 18, 2008 2:11 pm Post subject: |
|
|
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 |
|
 |
blackmorpheus Expert Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 159
|
Posted: Thu Dec 18, 2008 2:36 pm Post subject: |
|
|
| Cool tnx. I didnt know windows had these functions ( i/o library) !
|
|
| Back to top |
|
 |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Thu Dec 18, 2008 4:29 pm Post subject: |
|
|
| 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 |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu Dec 18, 2008 4:37 pm Post subject: |
|
|
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 |
|
 |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Thu Dec 18, 2008 4:54 pm Post subject: |
|
|
| 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 |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Thu Dec 18, 2008 5:02 pm Post subject: |
|
|
| 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 |
|
 |
|