組み込みのライブラリか何かを使用して、文字列を正規表現で分割する必要があります。
a を使用する代わりに、 a をchar[]使用しstringます。それに変換するのは簡単char[]で、おそらく最初は文字列だったので、それを先に切り取った方がよいでしょう。
を形成するvector<string>には、次のことを行う必要があります。
#include <regex.h>
#include <string.h>
#include <vector.h>
using namespace std;
vector<string> split(string s){
regex r ("\\w+"); //regex matches whole words, (greedy, so no fragment words)
regex_iterator<string::iterator> rit ( s.begin(), s.end(), r );
regex_iterator<string::iterator> rend; //iterators to iterate thru words
vector<string> result<regex_iterator>(rit, rend);
return result; //iterates through the matches to fill the vector
}
それにはおそらく 1 つまたは 2 つのバグを解決する必要があり (私は少し錆びているだけです)、インライン ステートメントを使用して大幅に圧縮することもできます。
覚えておいてください: C++ の魔法は、反復子とインライン ステートメントの 2 つの形式で提供されます。