C++ split string by line

后端 未结 5 1458
我在风中等你
我在风中等你 2020-12-08 07:25

I need to split string by line. I used to do in the following way:

int doSegment(char *sentence, int segNum)
{
assert(pSegmenter != NULL);
Logger &log =          


        
5条回答
  •  半阙折子戏
    2020-12-08 07:34

    I'd like to use std::getline or std::string::find to go through the string. below code demonstrates getline function

    int doSegment(char *sentence)
    {
      std::stringstream ss(sentence);
      std::string to;
    
      if (sentence != NULL)
      {
        while(std::getline(ss,to,'\n')){
          cout << to <

提交回复
热议问题