Thread: Tokenizing a string

  1. #1
    Registered User
    Join Date
    Sep 2008

    Tokenizing a string

    Hey, I just moved from C to C++ I got a very small problem.

    Say I want to take a fraction as an input -> i.e. 4/8

    Is there a way using strings to split it at the '/' or do I need to use C strings?

    If so how do I convert them, and do I need to include any C libraries? (string.h for example?)

    I have seen some examples but can't get them to work.

    Would it be easier (and possible) to take the input in a char* in the first place?

    Thanks in advance.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    If you trust the user, you can read number << character << number. Check that the character is '/' as a precaution. As far as splitting C++ strings, you've got find and copy

  3. #3
    Registered User
    Join Date
    Sep 2008
    Ok cool, that works

    Hopefully I have no more questions but if so I will just update this thread.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Only if the question pertain to this topic should you add them here. Otherwise you are not labelled a spammer for separating new topics into new threads (which is generally better since the boards are also a repository of knowledge).

    Also check out the stringstream class.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM