In my program I receive a string: "09:07:38,50,100"
(the numbers will be changing, only commas are consistent)
My desired output would be separating the string into 3 different variables for use in other things.
like so:
a = 09:07:38
b = 50
c = 100
Currently I tried splitting the string by separating it at commas, but I still lack the ability to put the data into different variables, or at least the knowledge on how to.
Here is my current code:
#include<iostream>
#include<vector>
#include<sstream>
int main() {
    std::string my_str = "09:07:38,50,100";
    std::vector<std::string> result;
    std::stringstream s_stream(my_str); //create stringstream from the string
    
    while(s_stream.good()){
        std::string substr;
        getline(s_stream, substr, ','); //get first string delimited by comma
        result.push_back(substr);
    }
    
    for(int i = 0; i<result.size(); i++){ //print all splitted strings
        std::cout << result.at(i) << std::endl; 
    }
    
}
 
     
     
     
    