Last active
December 28, 2015 18:39
-
-
Save inaz2/7544606 to your computer and use it in GitHub Desktop.
C++11: use "range-based for" with argv
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
$ g++ --version | |
g++ (GCC) 4.7.3 | |
Copyright (C) 2012 Free Software Foundation, Inc. | |
This is free software; see the source for copying conditions. There is NO | |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
$ g++ --std=c++11 -o hello hello.cpp | |
$ ./hello reni kanako shiori ayaka momoka | |
Hello, reni! | |
Hello, kanako! | |
Hello, shiori! | |
Hello, ayaka! | |
Hello, momoka! |
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 <vector> | |
#include <string> | |
using namespace std; | |
int main(int argc, char** argv) | |
{ | |
vector<string> args(argv+1, argv+argc); | |
for (auto str : args) { | |
cout << "Hello, " << str << "!" << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment