I don't understand how "auto" work !! Can anyone explain it to me ?! Thank you very much.
I don't understand how "auto" work !! Can anyone explain it to me ?! Thank you very much.
| # | User | Rating |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | AmShZ | 147 |
| 4 | maspy | 147 |
| 6 | Um_nik | 144 |
| 7 | Errichto | 139 |
| 8 | adamant | 136 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
| Name |
|---|



tuong cai gi chu ham nay tao cung khong biet
What language are you speaking??
for example you have
set <int> s;you can write this
for (auto i:s)cout<<i<<" ";instance offor (set<int>::iterator i=s.begin();i!=s.end();i++)cout<<*i<<" "range based for
for (type var: collection)and auto keyword are actually not the same featureautois a new concept (to what I remember) that came from C++11. Theautovariable, when intialized (and assigned a value), is automatically given a type. For example,auto i = a.begin()withvector<int> aand you will have astd::vector<int>::iteratorvariablei. Useful isn't it?Imagine
will be replaced efficiently with
(well, think of a
listrather than avector.) Or, a little off-topic, this with C++11:There are also more things you can do with
autoHope this helps
^_^Regarding the example:
AFAIK, i is not an iterator here but an actual value. So, for example to print it you would use something like
cout << i;rather thancout << *i;.Also if a was a map, i would be of type
pair, with with i.first being a key from the map and i.second being the value for that key.