Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ignoring the Voices: C++11 Example - Using auto
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void cpp_old()
{
std::vector<std::string> my_collection;
my_collection.push_back("Hello");
my_collection.push_back("World");
for (std::vector<std::string>::iterator it = my_collection.begin(); it != my_collection.end(); ++it)
{
cout << *it << endl;
}
}
void cpp_new()
{
std::vector<std::string> my_collection;
my_collection.push_back("Hello");
my_collection.push_back("World");
for (auto it = my_collection.begin(); it != my_collection.end(); ++it)
{
cout << *it << endl;
}
}
int main()
{
cout << "Without using auto keyword" << endl;
cpp_old();
cout << "Using auto keyword" << endl;
cpp_new();
}
Owner

Compiled as follows:

g++ -std=c++0x -Wall -Werror -o using_auto using_auto.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment