noob question: how do i state a variable is a string?

This is a discussion on noob question: how do i state a variable is a string? within the C++ Programming forums, part of the General Programming Boards category; title is question... and if you want to be really helpfull can you tell me what some other ones are ...

  1. #1
    PHP
    PHP is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    41

    noob question: how do i state a variable is a string?

    title is question... and if you want to be really helpfull can you tell me what some other ones are that are usefull
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    You have to bring the string code into your program, so up at the top put:

    Code:
    #include <string>
    
    using std::string;
    And thenwhen you need a string just use it as a type, a la:

    Code:
    string thisIsAString = "Isn't it lovely?";

  3. #3
    PHP
    PHP is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    41
    thanx, that helps but i also am wondering, like i stat an integer with
    int variable name = name;
    but how would i say its not just a number but that its a full word (no spaces) and then whats the other thing for stating that it does have spaces?..
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    18
    I'm new to programming but isn't a space considered a character.

  5. #5
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    An int is a numeric data type. It holds numbers.

    If you want a word, you will need to use a variable of type string, which is the data type for strings.

    Code:
    int foo = 756 // Good, int is a number
    
    foo = "Hello there" // BAD - variables of type int are for numbers
    
    string bar = "This is my string" // Good, string held in string variable
    
    bar = "4532" // Works, but stores the string representation, NOT then numeric value.

  6. #6
    PHP
    PHP is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    41
    thanx a bunch dude, thats exactly what i need!
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  4. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 01:56 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21