C++11 auto

closed account (jwkNwA7f)
How can I use auto in C++11? I have just started learning the new features in C++11.

Thank you!
auto just deduces the type based on initialization.
1
2
3
auto integer = 3; //int
auto character = 'g'; //char
auto decimal = 3.4; //double 


It's typically useful for long typenames, e.g.
1
2
3
4
5
6
//Instead of
std::vector<std::list<std::chrono::nanoseconds> > raw_data;
std::vector<std::list<std::chrono::nanoseconds> >::iterator
   trial_iter = raw_data.begin();
//You can use
auto trial_iter = raw_data.begin();
closed account (jwkNwA7f)
I think I understand.

So, it can be a character, integer, float, or other variable depending on the value assigned to it?
closed account (jwkNwA7f)
Okay, thank you for your help!
Topic archived. No new replies allowed.