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

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

        <bdo id='vHv1h'></bdo><ul id='vHv1h'></ul>
      <legend id='vHv1h'><style id='vHv1h'><dir id='vHv1h'><q id='vHv1h'></q></dir></style></legend>

      1. C++ 有免费的函数`size(object)`吗?

        Does C++ have a free function `size(object)`?(C++ 有免费的函数`size(object)`吗?)
      2. <tfoot id='5zUpk'></tfoot>

          • <bdo id='5zUpk'></bdo><ul id='5zUpk'></ul>

              <legend id='5zUpk'><style id='5zUpk'><dir id='5zUpk'><q id='5zUpk'></q></dir></style></legend>
            1. <small id='5zUpk'></small><noframes id='5zUpk'>

                <tbody id='5zUpk'></tbody>

              • <i id='5zUpk'><tr id='5zUpk'><dt id='5zUpk'><q id='5zUpk'><span id='5zUpk'><b id='5zUpk'><form id='5zUpk'><ins id='5zUpk'></ins><ul id='5zUpk'></ul><sub id='5zUpk'></sub></form><legend id='5zUpk'></legend><bdo id='5zUpk'><pre id='5zUpk'><center id='5zUpk'></center></pre></bdo></b><th id='5zUpk'></th></span></q></dt></tr></i><div id='5zUpk'><tfoot id='5zUpk'></tfoot><dl id='5zUpk'><fieldset id='5zUpk'></fieldset></dl></div>
                  本文介绍了C++ 有免费的函数`size(object)`吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  似乎大多数人找到 string 大小的方式是他们只使用 my_string.size() 并且它工作正常.嗯,我最近为我做过的班级做了一个作业...

                  It seems that the way that most people find the size of a string is they just use the my_string.size() and it works fine. Well, I recently did an assignment for class where I did...

                  if (size(my_string) < 5)
                      store[counter].setWeight(stoi(my_string));
                  

                  而不是......

                  if (my_string.size() < 5)
                      store[counter].setWeight(stoi(my_string));
                  

                  但令我惊讶的是,我认为正在运行旧编译器的讲师无法运行该行代码.在我的编译器上,它是双向的,我不太确定为什么.

                  But to my suprise my instructor, who I believe is running an older compiler, wasn't able to run that line of code. On my compiler it works both ways and I'm not quite sure why.

                  一个完整的程序(两者都输出 4):

                  A complete program (it outputs 4 for both):

                  #include <string>
                  #include <iostream>
                  using namespace std;
                  
                  int main()
                  {
                      string myvar = "1000";
                      cout << "Using size(myvar) = " << size(myvar) << endl;
                      cout << "Using myvar.size() = " << myvar.size() << endl;
                  }
                  

                  如果有人能解释为什么我的问题解决方案适用于我的机器而不适用于我的教授?另外,我目前正在运行 VS2015.

                  If anyone can shed some light on why my solution to the problem worked on my Machine but not my Professors? Also, I'm currently running VS2015.

                  推荐答案

                  MSVS 2015 在 xutility 中定义了一个 size 函数

                  MSVS 2015 has a size function defined in xutility

                  template<class _Container>
                  auto inline size(const _Container& _Cont)
                      -> decltype(_Cont.size())
                  {   // get size() for container
                  return (_Cont.size());
                  }
                  

                  这是调用时正在使用的函数

                  This is the function that is being used when you call

                  cout << "Using size(myvar) = " << size(myvar) << endl;
                  

                  这不是标准的 C++11/14 函数,不会在 gcc 上运行a> 或 clang

                  This is not a standard C++11/14 function and will not run on gcc or clang

                  这在博客文章 VS 2015 RTM 中的 C++11/14/17 特性

                  这篇关于C++ 有免费的函数`size(object)`吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                  • <tfoot id='69Qtc'></tfoot>

                      • <bdo id='69Qtc'></bdo><ul id='69Qtc'></ul>
                          <tbody id='69Qtc'></tbody>

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