Thread: isspace() is the way!

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    isspace() is the way!

    Hi there!
    I have a "little" problem..

    I want the user to input a string and a number value associated to it..
    like this :

    pi 3.1416

    so I want to put those variable in a map<string,float>

    so guessed I could put the first value all together in a temp string, then sort it out afterward.
    using something like cin.get and isspace().
    So basuically I need a way to go through a string until a white-space is encoutered. Put the first value into another string (map) and put whatever else is after in float(map)...?

    any sugestions?

    Luigi

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    You could use the default behavior of cin to your advantage...

    Code:
    cout << "Please enter a string, and a float  (example: pi 3.14): ";
    float temp_float;
    string temp_string;
    
    cin >> temp_string >> temp_float;
    // put them on the map or whatever
    cin will read up to a space and store it in temp_string, then store the rest in temp_float.

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    or just read char by char with cin.get() as you wish... then if the read char == ' ' just ignore it, what exactly is your problem?
    none...

  4. #4
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    ho didnt knew I could use cin that way (input 2 things on one line)
    that should do it, thx..

    As for ammar Im just not sure how to read char by char..

    Luigi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. for and isspace
    By izzy in forum C Programming
    Replies: 2
    Last Post: 03-15-2009, 06:18 PM
  2. pointer with isspace()
    By aze in forum C Programming
    Replies: 6
    Last Post: 04-17-2004, 09:43 PM
  3. Isspace ??? Anyone Know?
    By justin69enoch in forum C Programming
    Replies: 12
    Last Post: 01-23-2003, 05:02 PM
  4. Need help.
    By geetee in forum C Programming
    Replies: 6
    Last Post: 10-16-2001, 09:51 PM