Created
November 6, 2011 20:51
-
-
Save dazfuller/1343463 to your computer and use it in GitHub Desktop.
Ignoring the Voices: C++11 Example - Using auto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled as follows:
g++ -std=c++0x -Wall -Werror -o using_auto using_auto.cpp