title: How can I get the size of an std::vector as an int?
body: <p>I tried:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  int main () {
      std::vector&lt;int&gt; v;
      int size = v.size;
  }
  </code></pre>
  
  <p>but got the error:</p>
  
  <pre><code>cannot convert 'std::vector&lt;int&gt;::size' from type 'std::vector&lt;int&gt;::size_type (std::vector&lt;int&gt;::)() const noexcept' {aka 'long unsigned int (std::vector&lt;int&gt;::)() const noexcept'} to type 'int'
  </code></pre>
  
  <p>Casting the expression to <code>int</code> like this:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  int main () {
      std::vector&lt;int&gt; v;
      int size = (int)v.size;
  }
  </code></pre>
  
  <p>also yields an error:</p>
  
  <pre><code>error: invalid use of member function 'std::vector&lt;_Tp, _Alloc&gt;::size_type std::vector&lt;_Tp, _Alloc&gt;::size() const [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::size_type = long unsigned int]' (did you forget the '()' ?)
  </code></pre>
  
  <p>Last I tried:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  int main () {
      std::vector&lt;int&gt; v;
      int size = v.size();
  }
  </code></pre>
  
  <p>which gave me:</p>
  
  <pre><code>warning: implicit conversion loses integer precision
  </code></pre>
  
  <p>How can I fix this?</p>