Thread: Strings

  1. #1
    Registered User
    Join Date
    May 2006


    I use Visual C++. Is there a string class in STL so that i can use it for data type identifier for example like "string my_variable;". And one more question: How is it possible to convert a string value to double or float? can any one show me the simplest pseudocode?


  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    The STL string is in the header file "string" so just:

    #include <string>
    Look up stringstreams for converting strings to X data type.

    EDIT: Don't forget string is in the std namespace.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Registered User
    Join Date
    Jan 2005
    The simplest pseudocode might be:

    std::istringstream istr(myStringVar);
    istr >> myDoubleVar;

    Although you might want to add error checking. You can also use atoi or atof if you don't care about error checking: myDoubleVar = std::atof(myStringVar.c_str());

  4. #4
    Registered User
    Join Date
    May 2006
    what are delimiters and tokeniser???

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    A delimeter is a character that marks the end (or beginning) of a piece of data. If we had the string:

    "The quick brown fox jumps over the lazy dog."

    and we read to the delimeter 'x', we would have

    "The quick brown fo"

    A token is essentially the data that exists between the delimeters. A tokenizer is an algorithm that parses a string into tokens. If we were to use a tokenizer on the string:


    with the delimeters being '-' and "=", then we would get the resulting tokens, "2x","12", and "48".
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    May 2006
    I am satisfied with the explanation. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM