[Solved] Extracting string from text [closed]


Not the most elegant solution but this should work

#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

vector<string> split(string str, char delimiter)
{
    vector<string> internal;
    stringstream ss(str); 
    string tok;

    while(getline(ss, tok, delimiter))
    {
        internal.push_back(tok);
    }

    return internal;
}

int main(int argc, char **argv)
{

    string str = "My name is bob.I am fine";
    for(int i = 0; i < str.length(); i++)
    {
        if(str[i] == '.')
        {
            str.insert(i++," ");
            str.insert(++i," ");
        }
    }
    vector<string> sep = split(str, ' ');


    for(string t : sep)
        cout << t << endl;
}

solved Extracting string from text [closed]