Skip to content

Instantly share code, notes, and snippets.

@xunkai55
Created October 21, 2015 05:10
Show Gist options
  • Save xunkai55/ef961e2c390b0d0f1c6a to your computer and use it in GitHub Desktop.
Save xunkai55/ef961e2c390b0d0f1c6a to your computer and use it in GitHub Desktop.
Use a pointer to directly manipulate elements in an STL map
#include <iostream>
#include <map>
using namespace std;
struct S{
int data;
float f;
S(int d, float x): data(d), f(x) {}
S(): data(0), f(0) {}
};
int main() {
// your code goes here
std::map<int, S> m;
m.emplace(1, S(2, 3));
m.emplace(3, S(4, 5));
S *s = &m.at(3);
s->f = 6;
cout << m[3].f << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment