Created
June 2, 2011 16:41
-
-
Save mastbaum/1004773 to your computer and use it in GitHub Desktop.
Setting STL vector elements with at
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
/** The name of std::vector::at makes it sound like it's a "getter" only. | |
* Can I set "v.at(i) = a" like I would "v[i] = a" ? | |
* | |
* Yes. | |
*/ | |
int main() | |
{ | |
std::vector<int> a(5); | |
a.at(3) = 7; | |
std::vector<int>::iterator it; | |
for(it = a.begin(); it < a.end(); it++) | |
std::cout << *it << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment