-
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
-
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.
-
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?
-
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