Last Updated 2011/12/07
Programming Tips C++  索 引 
C++ で文字列分割 split
2011/12/07

他の言語では split があるのに C++ にはないから作ってみました.

#include 
#include 
using namespace std;

vector split(string strOrg, string strDiv)
{
    vector astrRet;
    int iCnt;
    int iFind;
    for( iCnt = 0; iCnt <= strOrg.length(); iCnt = iFind + 1 ){
        iFind = strOrg.find_first_of( strDiv, iCnt );
        if( iFind == string::npos ) iFind = strOrg.length();
        astrRet.push_back( strOrg.substr( iCnt, iFind - iCnt ) );
    }
    return astrRet;
}


参照
前後のTips
C++ で文字列分割 split

DSS ProgrammingTipsCGI Ver2.02