CArray - GetUpperBound [英] CArray - GetUpperBound

查看:83
本文介绍了CArray - GetUpperBound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i对GetUPPerBound有什么疑问GetUPPerBound和GetSize之间的区别怎么办vector c ++ getupperbound

Hi all,

i have doubt regarding GetUPPerBound whats the difference between GetUPPerBound and GetSize how to do do in vector c++ getupperbound

推荐答案

CArray :: GetUpperBound()用于获取数组的UpperBound(数组的最后一个索引)。

因为数组索引从零开始,所以此函数返回值小于GetSize。

当数组不包含任何元素时,GetUpperBound()得-1。

CArray::GetUpperBound() is used to get the UpperBound of the array(last index of the array).
Because array indexes are zero-based, this function returns a value 1 less than GetSize.
GetUpperBound( ) give –1 when array contains no elements.
CArray<cpoint,cpoint> myArray;
CPoint pt;
for (int i = 0; i < 10; i++)
   myArray.Add(CPoint(i, 2 * i));
for (int i = 0; i <= myArray.GetUpperBound(); i++)
{
   pt = myArray.GetAt(i);
   pt.x = 0;
   myArray.SetAt(i, pt);
}



CArray :: GetSize()返回数组大小。因为索引是从零开始的,所以大小比最大索引大1。调用此方法将生成与CArray :: GetCount方法相同的结果。


CArray::GetSize() return the size off array.Because indexes are zero-based, the size is 1 greater than the largest index. Calling this method will generate the same result as the CArray::GetCount method.

CArray<cpoint,cpoint> myArray;
for (int i = 0; i < 10; i++)
   myArray.Add(CPoint(i, 2*i));
for (int i = 0; i < myArray.GetSize(); i++)
{
   CPoint& pt = myArray.ElementAt(i);
   pt.x = 0;
}





您可以为Vectors调用size()函数。



You can call size() function for Vectors.

#include <iostream>
#include <vector>
int main ()
{
  std::vector<int> myints;
  std::cout << "0. size: " << myints.size() << '\n';
  for (int i=0; i<10; i++) myints.push_back(i);
  std::cout << "1. size: " << myints.size() << '\n';
  myints.insert (myints.end(),10,100);
  std::cout << "2. size: " << myints.size() << '\n';
  myints.pop_back();
  std::cout << "3. size: " << myints.size() << '\n';
  return 0;
}


这篇关于CArray - GetUpperBound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆