+ 1
what's the use of auto in C++?
2 Antworten
+ 3
It automatically detect type of variable. For example:
auto x = 1; generates int variable
It is useful for foreach loops in C++11 when we doesn't know what type of variable has vector.:
std::vector<int> v(10, 0);
for (auto i : v)
std::cout << i;
+ 2
If you don't care about the type or it's obvious, use auto.