Thread: A string/int variable

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    10

    A string/int variable

    Is there a variable that can hold string and int in the same time?
    If not, what can I do if I want to input data with string and int like a password for an example.

  2. #2
    Registered User
    Join Date
    Jul 2013
    Posts
    158
    Why you wants to do so?
    You can ask for it separately instead of in pair.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    10
    I know that but what if someone wants to make a username or a password that contains letters and numbers.
    How can I make the program accept such data.
    Thank you.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    What you are thinking of as "number" is just convention of numerals.

    The C++ notion of `int' and `std::string' are different types of objects which also have conventions.

    The "values" "one" and "1" both represent the same thing by convention, but both are composed of "glyphs" representing characters with which you are familiar.

    Each of 'o', 'n', 'e', and '1' are all just----type `char'--characters, and in C++, `std::string' is a collection of characters.

    If you can express what you are thinking of in terms of "these are characters", you can just use a `std::string' to store the information.

    You do not need to interpret "one1" as a `std::string' and an `int'; you can just store the value as a `std::string' and interpret the value as four different characters.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. assign string to the string variable inside structure!
    By king_zart in forum C++ Programming
    Replies: 20
    Last Post: 12-09-2012, 11:37 AM
  2. Variable In SQL String
    By mcertini in forum C++ Programming
    Replies: 3
    Last Post: 03-24-2011, 02:24 AM
  3. string as a variable name
    By violatro in forum C Programming
    Replies: 4
    Last Post: 06-01-2010, 01:01 AM
  4. Replies: 12
    Last Post: 10-14-2003, 10:17 AM
  5. string variable used as a variable...
    By Supar in forum C++ Programming
    Replies: 13
    Last Post: 03-29-2003, 04:21 PM