October 11th, 2002, 11:21 PM
in C++, what data type will store both numbers and characters? so that you could input IP addresses or handles or something that contained both?
There are 10 types of people in this world, The ones that understand binary and the ones that dont.
October 12th, 2002, 01:08 AM
you could use type char[size] or string or char*. Note with those you would have to check if the value contained is numeric or alpha. If your working on *nix and want to work with things such as ip address check out socket.h. You could also build your own class to handle it the types.
Hope that helps.
If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
-- former White House cybersecurity adviser Richard Clarke
October 12th, 2002, 01:17 AM
characters will store numbers and characters, because numbers are represented by characters like "4" and "7" just like 'characters' (letters) are stored as characters like "a" or "G" or ">" for that matter.
however if you make a character array, or #include the string library and use a "string" datatype, you can then hold characters.
When you want to perform an arithmetic operation on a character ( or string[x] ), you can cast the character "7" as the integer "7". or with any number or letter or even symbol.
char characterNAME = '2' ;
int integerNAME = 3 ;
cout << integerNAME + int(characterNAME) ;
the output should be 5 naturally, unless you changed the value for 2 or 3.
cast integers as characters:
int ONE = 1 ;
char characterstoredinONE = char(ONE) ;
thank you, and </day> goodnight...
Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!
October 12th, 2002, 01:21 AM
C++ doesn't have a string <variable> datatype per se. thats VB. If you would like to use the standard library you could use this:
// that variable will now be of string datatype.
or if you want to be more traditional you could use something like.
#define STR_LEN 80
// this will hold up to an 80 character string, (which you can adjust for your needs) plus the NULL terminator. i.e. \0.
Hope this helps.
October 12th, 2002, 01:39 AM
The header file <string> holds a class for a string type in C++:
my_string_var = "My string data";
However I'd agree, that it would probably be best to create your own class to handle the data types