|
-
April 15th, 2002, 06:02 AM
#1
vector at
how to use vector.at
i try this and doesn't work
mt arr has 100000 objects
void CTestDlg::OnButton1()
{
CString s;
s.Format("\n%d", arr.at(49999).Xdeg);
AfxMessageBox(s);
}
-
April 15th, 2002, 01:02 PM
#2
Re: vector at
#include <vector>
#include <iostream>
#include <exception>
#include <conio.h>
int main()
{
std::vector<int> vecInteger;
// Fill vector
for(int iIndex = 0; iIndex < 50; ++iIndex)
vecInteger.push_back(iIndex);
// Get one element
try
{
std::cout << vecInteger.at(20) << std::endl;
}
catch(const std: ut_of_range &)
{
std::cout << "Out of range access" << std::endl;
}
// Wait for keystroke
_getch();
return 0;
}
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
-
April 15th, 2002, 01:13 PM
#3
Re: vector at
What do you mean "it doesn't work?". Please be more specific. Accessing object 49,999 from a vector of 100,000 is *not* the problem -- it is somewhere else. I can't compile your code because of the following:
a) what is arr a vector of? int's, double's, widgets?
b) what is Xdeg? Please show the structure that you are referring to.
b) How do you initialize this vector? Are you sure it contains 100000 objects?
Basically, show the miminal amount of code that lets everyone see what you're talking about.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|