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

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

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

        C++11 std::to_string(double) - 没有尾随零

        时间:2024-05-11

          <bdo id='7ddsr'></bdo><ul id='7ddsr'></ul>
          <legend id='7ddsr'><style id='7ddsr'><dir id='7ddsr'><q id='7ddsr'></q></dir></style></legend><tfoot id='7ddsr'></tfoot>

                <tbody id='7ddsr'></tbody>

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

                <small id='7ddsr'></small><noframes id='7ddsr'>

                1. 本文介绍了C++11 std::to_string(double) - 没有尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  今天尝试了C++11 STL的一些新函数,遇到了std::to_string.

                  Today I tried out some new functions of the C++11 STL and encountered std::to_string.

                  可爱、可爱的功能集.为一个双字符到字符串的转换创建一个 stringstream 对象对我来说总是显得有些矫枉过正,所以我很高兴我们现在可以做这样的事情:

                  Lovely, lovely set of functions. Creating a stringstream object for just one double-to-string conversion always seemed overkill to me, so I'm glad we can now do something like this:

                  std::cout << std::to_string(0.33) << std::endl;
                  

                  结果?

                  0.330000
                  

                  我对此并不完全满意.有没有办法告诉 std::to_string 去掉尾随的零?我在互联网上搜索过,但据我所知,该函数只接受一个参数(要转换的值).回到使用 stringstreams 的过去",您可以设置流的宽度,但我不想转换回来.

                  I'm not entirely content with that. Is there a way to tell std::to_string to leave out the trailing zeros? I searched the internet, but as far as I can see the function takes only one argument (the value to be converted). Back in 'the old days' with stringstreams, you could set the width of the stream, but I'd rather not convert back.

                  有人遇到过这个问题/有解决方案吗?一些 StackOverflow 搜索没有结果.

                  Anyone encountered this problem before/has a solution? Some StackOverflow searches yielded nothing.

                  (C++11 STL 参考:http://en.cppreference.com/w/cpp/string/basic_string/to_string)

                  (A C++11 STL reference: http://en.cppreference.com/w/cpp/string/basic_string/to_string)

                  推荐答案

                  C++11 标准明确规定 (21.5/7):

                  The C++11 Standard explicitely says (21.5/7):

                  返回:每个函数返回一个字符串对象,其中包含其参数值的字符表示,该值将通过调用 sprintf(buf, fmt, val) 生成,格式说明符为%d"、%u",分别为 "%ld"、"%lu"、"%lld"、"%llu"、"%f"、"%f" 或 "%Lf",其中 buf 指定足够大小的内部字符缓冲区

                  Returns: Each function returns a string object holding the character representation of the value of its argument that would be generated by calling sprintf(buf, fmt, val) with a format specifier of "%d", "%u", "%ld", "%lu", "%lld", "%llu", "%f", "%f", or "%Lf", respectively, where buf designates an internal character buffer of sufficient size

                  对于按此顺序声明的函数:

                  for the functions declared in this order:

                  string to_string(int val);
                  string to_string(unsigned val);
                  string to_string(long val);
                  string to_string(unsigned long val);
                  string to_string(long long val);
                  string to_string(unsigned long long val);
                  string to_string(float val);
                  string to_string(double val);
                  string to_string(long double val);
                  

                  因此,您无法控制结果字符串的格式.

                  Thus, you cannot control the formatting of the resulting string.

                  这篇关于C++11 std::to_string(double) - 没有尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:与 win32 CRITICAL_SECTION 相比的 std::mutex 性能 下一篇:如何检查传递的 Iterator 是否为随机访问迭代器?

                  相关文章

                2. <small id='vUK77'></small><noframes id='vUK77'>

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

                5. <tfoot id='vUK77'></tfoot>