Skip to content

Instantly share code, notes, and snippets.

@mastbaum
Created June 2, 2011 16:41
Show Gist options
  • Save mastbaum/1004773 to your computer and use it in GitHub Desktop.
Save mastbaum/1004773 to your computer and use it in GitHub Desktop.
Setting STL vector elements with at
#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