[ create a new paste ] login | about

Link: http://codepad.org/r57r4SCX    [ raw code | output | fork ]

C++, pasted on Aug 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

int main(){
std::string str = "[0.0, 2.1, 22.3]";
   std::vector<std::string> v ; //Use vector to add the words

    std::size_t prev_pos = 0, pos;
    while ((pos = str.find_first_of("[] ,", prev_pos)) != std::string::npos)
    {
        if (pos > prev_pos)
            v.push_back(str.substr(prev_pos, pos-prev_pos));
        prev_pos= pos+1;
    }
    if (prev_pos< str.length())
        v.push_back(str.substr(prev_pos, std::string::npos));


std::cout << v << std::endl;

}


Output:
1
[0.0, 2.1, 22.3]


Create a new paste based on this one


Comments: