Skip to content

Instantly share code, notes, and snippets.

@inaz2
Last active December 28, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inaz2/7544606 to your computer and use it in GitHub Desktop.
Save inaz2/7544606 to your computer and use it in GitHub Desktop.
C++11: use "range-based for" with argv
$ 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!
#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