-
A Little Help!?!?
Hey people, I need some help, I got a new book, and it tells right off the bat to do this to write out all the ASCII characters:
PHP Code:
#include <iostream>
main <void>
{
unsigned char ASCIIValue = 0;
while (ASCIIValue < 256)
std::cout.put (ASCIIValue);
ASCIIValue ++;
return 0;
}
Ok so why the hell dose it not work, this book is using VC++, and im using the same complier, so could osme one plz tell me ***?
Gives errors do to ";" not being behind < or something.
-
int main(void)
instead of
main <void>
-
Re: A Little Help!?!?
Code:
#include <iostream>
int main (void)
{
unsigned char ASCIIValue = 0;
while (ASCIIValue <= 255)
{
std::cout.put (ASCIIValue);
ASCIIValue ++;
}
return 0;
}
You forgot to put curly brackets for the while loop
Edited: the upper limit of unsigned char is 255
-
If what you first posted is what your book told you to do then throw it away.
-
Or send it to me so I can televise its ritual destruction, followed by posting the pieces to the publisher.
:)
-
How about ritually destructing the author?
-
lol yeah it was a type from the book..
-
-
Bad enough that a c++ book gives main no return type. That's a very bad manner that shouldn't even be started.
-
I know what you mean, it should have been left main ().
-
No he means the return type, like
I guess.
-
I know I meant the return type, thats why I said leave it empty instead of putting void main ( ) main (void)
-
Leave what empty?
The definition is:
Code:
int main(int argc, char **argv);
You can miss off argv, or argc AND argv. Since we're talking about C++, a blank argument list () is acceptable. In C, if main did not require arguments, it should be given as:because in C, a blank argument list means it can take any number, rather than taking none, as in C++.
-
it could still have been a typo, because there's return 0;
what does the other examples in the book have?
-
Don't they ever take a look at their books?