本文介绍了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<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!