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

  • <tfoot id='2SpAP'></tfoot>
      <bdo id='2SpAP'></bdo><ul id='2SpAP'></ul>

      <small id='2SpAP'></small><noframes id='2SpAP'>

        如何在一行上连接多个 C++ 字符串?

        How do I concatenate multiple C++ strings on one line?(如何在一行上连接多个 C++ 字符串?)
        1. <i id='WHvZy'><tr id='WHvZy'><dt id='WHvZy'><q id='WHvZy'><span id='WHvZy'><b id='WHvZy'><form id='WHvZy'><ins id='WHvZy'></ins><ul id='WHvZy'></ul><sub id='WHvZy'></sub></form><legend id='WHvZy'></legend><bdo id='WHvZy'><pre id='WHvZy'><center id='WHvZy'></center></pre></bdo></b><th id='WHvZy'></th></span></q></dt></tr></i><div id='WHvZy'><tfoot id='WHvZy'></tfoot><dl id='WHvZy'><fieldset id='WHvZy'></fieldset></dl></div>

            1. <tfoot id='WHvZy'></tfoot>

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

                  <bdo id='WHvZy'></bdo><ul id='WHvZy'></ul>

                    <tbody id='WHvZy'></tbody>

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

                  本文介绍了如何在一行上连接多个 C++ 字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  C# 有一个语法特性,您可以在一行中将多种数据类型连接在一起.

                  C# has a syntax feature where you can concatenate many data types together on 1 line.

                  string s = new String();
                  s += "Hello world, " + myInt + niceToSeeYouString;
                  s += someChar1 + interestingDecimal + someChar2;
                  

                  C++ 中的等价物是什么?据我所知,您必须在单独的行上完成所有操作,因为它不支持使用 + 运算符的多个字符串/变量.这还可以,但看起来不那么整洁.

                  What would be the equivalent in C++? As far as I can see, you'd have to do it all on separate lines as it doesn't support multiple strings/variables with the + operator. This is OK, but doesn't look as neat.

                  string s;
                  s += "Hello world, " + "nice to see you, " + "or not.";
                  

                  上面的代码产生了一个错误.

                  The above code produces an error.

                  推荐答案

                  #include <sstream>
                  #include <string>
                  
                  std::stringstream ss;
                  ss << "Hello, world, " << myInt << niceToSeeYouString;
                  std::string s = ss.str();
                  

                  看看 Herb Sutter 的这篇本周大师文章:庄园农场的字符串格式化程序

                  Take a look at this Guru Of The Week article from Herb Sutter: The String Formatters of Manor Farm

                  这篇关于如何在一行上连接多个 C++ 字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

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

                          <bdo id='CRLiS'></bdo><ul id='CRLiS'></ul>

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

                          <legend id='CRLiS'><style id='CRLiS'><dir id='CRLiS'><q id='CRLiS'></q></dir></style></legend>
                              <tbody id='CRLiS'></tbody>