Visual C++ 11では、TR1のregex_token_iteratorを使用できます。
sregex_token_iterator::regex_type white_space_separators("[[:space:]]+",regex_constants::optimize);
for(sregex_token_iterator i(s.begin(),s.()end,white_space_separators,-1),end; i!=end; i++)
{
cout << *i << endl;
// or use i.start, i.end which is faster access
}
パフォーマンス(と文字列のコピーのようなオーバーヘッド)を懸念し、あなたがあなた自身のルーチン書くことができた場合:[?C++で文字列を分割する方法]
#include <ctype.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s = "Text for tokenization ";
const char *start = s.c_str();
const char *end = start + s.size();
const char *token = start;
while (start!=end)
{
if(isspace(*start))
{
if (token < start)
{
// Instead of constructing string, you can
// just use [token,start] part of the input buffer
cout << string(token,start) << ' ';
}
start++;
token = start;
}
else
{
start++;
}
}
if (token < start)
{
cout << string(token,start) << ' ';
}
}
の可能な複製を( http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c) – user7116
私はこの質問がすでに数回尋ねられていると思います:http://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring http://stackoverflow.com/questions/4328685/input-line-by-line-from-an-input-file-and-tokenize-using-strtok-and-the-アウトプt http://stackoverflow.com/questions/536148/c-string-parsing-python-style http://stackoverflow.com/questions/1511029/c-tokenize-a-string-and-include-delimiters http:///stackoverflow.com/questions/3162108/a-better-way-to-split-a-string-into-an-array-of-strings-in-cc-using-whitespac –
ブーストはあなたの友人です – marcinj