<legend id='p9f7u'><style id='p9f7u'><dir id='p9f7u'><q id='p9f7u'></q></dir></style></legend><tfoot id='p9f7u'></tfoot>
    <bdo id='p9f7u'></bdo><ul id='p9f7u'></ul>
    1. <small id='p9f7u'></small><noframes id='p9f7u'>

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

      1. std::vector 到带有自定义分隔符的字符串

        时间:2023-09-15
          <tbody id='GOJ0h'></tbody>

        <tfoot id='GOJ0h'></tfoot>

        1. <small id='GOJ0h'></small><noframes id='GOJ0h'>

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

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

                • <bdo id='GOJ0h'></bdo><ul id='GOJ0h'></ul>
                • 本文介绍了std::vector 到带有自定义分隔符的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想使用自定义分隔符将 vector 的内容复制到一个长 string 中.到目前为止,我已经尝试过:

                  I would like to copy the contents of a vector to one long string with a custom delimiter. So far, I've tried:

                  // .h
                  string getLabeledPointsString(const string delimiter=",");
                  // .cpp
                  string Gesture::getLabeledPointsString(const string delimiter) {
                      vector<int> x = getLabeledPoints();
                      stringstream  s;
                      copy(x.begin(),x.end(), ostream_iterator<int>(s,delimiter));
                      return s.str();
                  }
                  

                  但我明白了

                  no matching function for call to ‘std::ostream_iterator<int, char, std::char_traits<char> >::ostream_iterator(std::stringstream&, const std::string&)’
                  

                  我试过 charT* 但我得到

                  I've tried with charT* but I get

                  error iso c++ forbids declaration of charT with no type
                  

                  然后我尝试使用 charostream_iterator(s,&delimiter)但我在字符串中得到了奇怪的字符.

                  Then I tried using char and ostream_iterator<int>(s,&delimiter) but I get strange characters in the string.

                  谁能帮我理解编译器在这里的期望?

                  Can anyone help me make sense of what the compiler is expecting here?

                  推荐答案

                  使用 delimiter.c_str() 作为分隔符:

                  Use delimiter.c_str() as the delimiter:

                  copy(x.begin(),x.end(), ostream_iterator<int>(s,delimiter.c_str()));
                  

                  那样,你会得到一个 const char* 指向字符串,这是 ostream_operator 期望从你的 std::string 得到的.

                  That way, you get a const char* pointing to the string, which is what ostream_operator expects from your std::string.

                  这篇关于std::vector 到带有自定义分隔符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何最优雅地获取 std::vector 缓冲区的地址开始 下一篇:无法从基类类型的指针访问派生类方法

                  相关文章

                  最新文章

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

                    <tfoot id='ciGBb'></tfoot>
                        <bdo id='ciGBb'></bdo><ul id='ciGBb'></ul>
                    1. <legend id='ciGBb'><style id='ciGBb'><dir id='ciGBb'><q id='ciGBb'></q></dir></style></legend>