data types
Results 1 to 5 of 5

Thread: data types

  1. #1
    Junior Member
    Join Date
    Aug 2002

    data types

    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.

  2. #2
    Senior Member
    Join Date
    Jul 2001
    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

  3. #3
    Senior Member
    Join Date
    Jun 2002
    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!

  4. #4
    Join Date
    Jul 2001
    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:

    #include <iostream>
    #include <string.h>



    std::string <variable>

    // that variable will now be of string datatype.


    or if you want to be more traditional you could use something like.

    #include <stdio.h>

    #define STR_LEN 80

    int main()


    char strIN[STR_LEN+1];

    // 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.

  5. #5
    Senior Member
    Join Date
    Nov 2001
    The header file <string> holds a class for a string type in C++:


    int main(){
    string my_string_var;

    my_string_var = "My string data";

    return 0;

    However I'd agree, that it would probably be best to create your own class to handle the data types

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts