argv is an array of pointers to raw strings, you cannot get a range from it directly.
You can convert it to std::vector<std::string>on the fly, which works with the for-range loop:
#include <iostream>
#include <string>
#include <vector>
int main (int argc, char const * const argv[])
{
for (auto && str : std::vector<std::string> { argv, argv + argc })
{
std::cout << "param: " << str << std::endl;
}
}
This uses std::vectorconstructor # 4 :
template< class InputIt >
vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
Creates a container with the contents of a range [first, last). [...]
source
share