<bdo id='MrVfc'></bdo><ul id='MrVfc'></ul>
    <tfoot id='MrVfc'></tfoot>

      <i id='MrVfc'><tr id='MrVfc'><dt id='MrVfc'><q id='MrVfc'><span id='MrVfc'><b id='MrVfc'><form id='MrVfc'><ins id='MrVfc'></ins><ul id='MrVfc'></ul><sub id='MrVfc'></sub></form><legend id='MrVfc'></legend><bdo id='MrVfc'><pre id='MrVfc'><center id='MrVfc'></center></pre></bdo></b><th id='MrVfc'></th></span></q></dt></tr></i><div id='MrVfc'><tfoot id='MrVfc'></tfoot><dl id='MrVfc'><fieldset id='MrVfc'></fieldset></dl></div>
    1. <small id='MrVfc'></small><noframes id='MrVfc'>

    2. <legend id='MrVfc'><style id='MrVfc'><dir id='MrVfc'><q id='MrVfc'></q></dir></style></legend>
      1. C++ 逐行拆分字符串

        C++ split string by line(C++ 逐行拆分字符串)
        <i id='PqVkO'><tr id='PqVkO'><dt id='PqVkO'><q id='PqVkO'><span id='PqVkO'><b id='PqVkO'><form id='PqVkO'><ins id='PqVkO'></ins><ul id='PqVkO'></ul><sub id='PqVkO'></sub></form><legend id='PqVkO'></legend><bdo id='PqVkO'><pre id='PqVkO'><center id='PqVkO'></center></pre></bdo></b><th id='PqVkO'></th></span></q></dt></tr></i><div id='PqVkO'><tfoot id='PqVkO'></tfoot><dl id='PqVkO'><fieldset id='PqVkO'></fieldset></dl></div>

        <small id='PqVkO'></small><noframes id='PqVkO'>

          • <tfoot id='PqVkO'></tfoot>

              <legend id='PqVkO'><style id='PqVkO'><dir id='PqVkO'><q id='PqVkO'></q></dir></style></legend>

                • <bdo id='PqVkO'></bdo><ul id='PqVkO'></ul>
                    <tbody id='PqVkO'></tbody>
                  本文介绍了C++ 逐行拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要逐行拆分字符串.我以前是这样做的:

                  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 = Logger::getLogger();
                  char delims[] = "
                  ";
                  char *line = NULL;
                  if (sentence != NULL)
                  {
                      line = strtok(sentence, delims);
                      while(line != NULL)
                      {
                          cout << line << endl;
                          line = strtok(NULL, delims);
                      }
                  }
                  else
                  {
                      log.error("....");
                  }
                  return 0;
                  }
                  

                  我输入我们是一体的.不,我们是."并调用 doSegment 方法.但是当我调试时,我发现句子参数是we are one.\nyes we are",并且拆分失败.有人可以告诉我为什么会发生这种情况,我应该怎么做.无论如何,我还可以使用其他方法在 C++ 中拆分字符串.谢谢!

                  I input "we are one. yes we are." and invoke the doSegment method. But when i debugging, i found the sentence parameter is "we are one.\nyes we are", and the split failed. Can somebody tell me why this happened and what should i do. Is there anyway else i can use to split string in C++. thanks !

                  推荐答案

                  我想使用 std::getline 或 std::string::find 来遍历字符串.下面的代码演示了 getline 函数

                  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,'
                  ')){
                        cout << to <<endl;
                      }
                    }
                  
                  return 0;
                  }
                  

                  这篇关于C++ 逐行拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                    <small id='z35BC'></small><noframes id='z35BC'>

                          <tbody id='z35BC'></tbody>
                        • <bdo id='z35BC'></bdo><ul id='z35BC'></ul>
                        • <tfoot id='z35BC'></tfoot>

                          • <legend id='z35BC'><style id='z35BC'><dir id='z35BC'><q id='z35BC'></q></dir></style></legend>
                            <i id='z35BC'><tr id='z35BC'><dt id='z35BC'><q id='z35BC'><span id='z35BC'><b id='z35BC'><form id='z35BC'><ins id='z35BC'></ins><ul id='z35BC'></ul><sub id='z35BC'></sub></form><legend id='z35BC'></legend><bdo id='z35BC'><pre id='z35BC'><center id='z35BC'></center></pre></bdo></b><th id='z35BC'></th></span></q></dt></tr></i><div id='z35BC'><tfoot id='z35BC'></tfoot><dl id='z35BC'><fieldset id='z35BC'></fieldset></dl></div>