|
-
August 28th, 2009, 02:49 PM
#1
seperate the string and store it in map
I am not sure how this works in VC6 as i am a new programmer...please help.
I have a string
"0.28813,0.30125,0.31813,0.45375,0.61313,0.84063,1.00938,1.16375,1.26"
i want to store each of the number into a map of < count, double>
Can someone tell me how to search the commas, read each of the numbers, store them as a double and push to store in a map?
Thank you!
-
August 28th, 2009, 02:53 PM
#2
Re: seperate the string and store it in map
You could used strtok and atof to split the string up and convert the pieces to double.
What do you mean by count as the map key?
-
August 28th, 2009, 02:54 PM
#3
Re: seperate the string and store it in map
Why are you using VC6? That's a dinosaur.
It's not clear what the "count" in your map is intended to be.
-
August 28th, 2009, 04:18 PM
#4
Re: seperate the string and store it in map
I also do not understand what the "count" is. To get the
double values: place the string into a stringstream and let
it do the parsing:
Code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string s = "0.28813,0.30125,0.31813,0.45375,0.61313,0.84063,1.00938,1.16375,1.26";
double value;
char c;
stringstream ss(s);
while (ss >> value)
{
cout << value << "\n";
ss >> c;
}
return 0;
}
-
August 28th, 2009, 05:07 PM
#5
Re: seperate the string and store it in map
You should probably add a check to verify that the c is always a comma.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|