C,C++, string split example source code (stringstream, getline functions)


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

using namespace std;

vector< string> str_split(const string &s, char delim) 
{
    vector< string> elems;
    stringstream ss(s);
    string item;
    
    while (getline(ss, item, delim)) {
        elems.push_back(item);
    }
 
    return elems;
}



int main()
{

 vector< string> str = str_split( "123,456", ',');
 for(int i=0; i< str.size(); ++i)
 {
  printf("%s\n", str[i].c_str() );
 }

}


Comments

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

AMP dose run on my pc?, AMP(Accelerated Massive Parallelism)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Optical Flow sample source code using OpenCV

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

OpenCV meanShiftFiltering example source code ( cpu: pyrMeanShiftFiltering, gpu:meanShiftFiltering, gpu:meanShiftSegmentation )

Image warping (using opencv findHomography, warpPerspective)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)