Search code examples
c++parsingmfccstring

CString Parsing Carriage Returns


Let's say I have a string that has multiple carriage returns in it, i.e:

394968686
100630382
395950966
335666021

I'm still pretty amateur hour with C++, would anyone be willing to show me how you go about: parsing through each "line" in the string ? So I can do something with it later (add the desired line to a list). I'm guessing using Find("\n") in a loop?

Thanks guys.


Solution

  • You could try it using stringstream. Notice that you can overload the getline method to use any delimeter you want.

    string line;
    stringstream ss;
    ss << yourstring;
    while ( getline(ss, line, '\n') )
    {
      cout << line << endl;
    }
    

    Alternatively you could use the boost library's tokenizer class.