I have a vector of string, vector <string> shapes holding these coordinates data:
Shape1, [3, 2]
Shape1, [6, 7]
Shape2, [7, 12, 3], [-9, 13, 68]
Shape1, [10, 3]
Shape2, [30, -120, 3], [-29, 1, 268]
Shape3, [15, 32], [1, 5]
Shape4, [24, 31, 56]
I am trying to cout the coordinates x and y from Shape1 and Shape3 and x, y, z from Shape2 and Shape4. This is a reproducible code:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    vector <string> shapes;
    
    shapes.push_back("Shape1, [3, 2]");
    shapes.push_back("Shape1, [632, 73]");
    shapes.push_back("Shape2, [7, 12, 3], [-9, 13, 68]");
    shapes.push_back("Shape1, [10, 3]");
    shapes.push_back("Shape2, [30, -120, 3], [-29, 1, 268]");
    shapes.push_back("Shape3, [15, 32], [1, 5]");
    shapes.push_back("Shape4, [24, 31, 56]");
    
    for(int i = 0; i < shapes.size(); i++)
    {
        // attempt to extract x
        size_t string_start = shapes[i].find(", [");
        string extracted = shapes[i].substr(string_start + 3, 1);
        
        cout << extracted << endl;
    }
    
    return 0;
}
As it is now, my current code can't cout the x properly - only the first character of x is cout. How should I handle the length of x? Subsequently, how should I cout the y and z in the data? The delimiter is , but there are multiples , everywhere.
 
     
     
    