| View previous topic :: View next topic |
| Author |
Message |
superfirepig Master Cheater
Reputation: 0
Joined: 07 Oct 2006 Posts: 313 Location: city of hackers
|
Posted: Wed Jan 23, 2008 11:02 am Post subject: [C++]bool |
|
|
Can anyone give me a definition of bool? I know it can break down a very long code to shorter lines but can anyone give me an example of when to use it and how to use it?
_________________
You don't have enough MP to f#@% me, please try again later |
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Wed Jan 23, 2008 11:09 am Post subject: |
|
|
Bool is shorten from Boolean. I dont know whenever you are familar with Booleans but however they can just have two values. Either true or false.
They are not really usefull and dont know why they exist.
| Code: | | bool LoggedIn = true; |
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
goldengold Grandmaster Cheater Supreme
Reputation: -1
Joined: 11 Nov 2006 Posts: 1841 Location: -.-
|
Posted: Wed Jan 23, 2008 12:10 pm Post subject: |
|
|
_________________
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Wed Jan 23, 2008 12:50 pm Post subject: |
|
|
bool female = true;
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Wed Jan 23, 2008 12:59 pm Post subject: |
|
|
| Naablet wrote: | Bool is shorten from Boolean. I dont know whenever you are familar with Booleans but however they can just have two values. Either true or false.
They are not really usefull and dont know why they exist.
| Code: | | bool LoggedIn = true; |
|
wut do u mean they're not really useful...
booleans are an easy simple way to get a true or false answer.
if you read some source code (for example some of Wiicaan's) they're obviously used a LOT.
_________________
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Wed Jan 23, 2008 2:23 pm Post subject: |
|
|
A bool can have only two values either true(1) or false(0). It is most commonly used to print error messages. It can be very useful to use when your working on bigger programs that have lots of room for errors.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Wed Jan 23, 2008 2:25 pm Post subject: |
|
|
Booleans are mostly used for conditional statements. Some people use it as an array to represent binary.
Example:
| Code: |
-Create a loop
-Show a menu
1) Something
2) Something
3) Exit
-Get input
-Do your code
bool isGoing = true;
while (isGoing)
{
// Display menu and get input
...
switch (<variable>)
{
// Insert for case 1 and 2
case 3:
isGoing = false; // this will end the loop
break;
}
}
|
Just for fun, you can use cout.setf(ios_base::boolalpha); to display the boolean as true or false instead of 1 or 0. You would put that statement in the beginning of main and only once.
| Code: |
#include <iostream>
int main (int argc, char *argv[])
{
std::cout.setf(std::ios_base::boolalpha)
...
return 0;
}
|
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Jan 24, 2008 6:55 pm Post subject: |
|
|
Booleans are probably one of the most used variable types.
Naablet, you should really stop posting just your opinion in all of your posts. You seem to say "not really useful" to a lot of things. That is your opinion, and your code style isn't the best either.
superfirepig, as the others have pointed out already, a boolean is a true / false variable type. The value can be seen as 0 or 1 as well. 0 being false, 1 being true.
_________________
- Retired. |
|
| Back to top |
|
 |
nox Expert Cheater
Reputation: 0
Joined: 09 Apr 2007 Posts: 227 Location: brooklyn
|
Posted: Sun Jan 27, 2008 6:36 pm Post subject: |
|
|
| Naablet wrote: |
bool female = true; |
fucking idiot
| Naablet wrote: |
They are not really usefull and dont know why they exist. |
fucking idiot
|
|
| Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Mon Jan 28, 2008 6:07 am Post subject: |
|
|
| nox wrote: | | Naablet wrote: |
bool female = true; |
fucking idiot
| Naablet wrote: |
They are not really usefull and dont know why they exist. |
fucking idiot |
fucking genius
_________________
CLICK TO HAX MAPLESTORAY ^ !!!! |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Mon Jan 28, 2008 2:28 pm Post subject: |
|
|
Fucking locked.
Just sounded good. Anyway, question was answered, things went into the wrong direction. Yadda yadda.
_________________
- Retired. |
|
| Back to top |
|
 |
|