将argv保存到向量或字符串 [英] Save argv to vector or string
本文介绍了将argv保存到向量或字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将所有参数保存到向量或类似的东西。我不是一个程序员,所以我不知道该怎么做,但这里是我到目前为止。我只想调用一个函数系统传递所有参数。
I need to save all arguments to a vector or something like this. I'm not a programmer, so I don't know how to do it, but here's what I've got so far. I just want to call a function system to pass all arguments after.
#include "stdafx.h"
#include "iostream"
#include "vector"
#include <string>
using namespace std;
int main ( int argc, char *argv[] )
{
for (int i=1; i<argc; i++)
{
if(strcmp(argv[i], "/all /renew") == 0)
{
system("\"\"c:\\program files\\internet explorer\\iexplore.exe\" \"www.stackoverflow.com\"\"");
}
else
system("c:\\windows\\system32\\ipconfig.exe"+**All Argv**);
}
return 0;
}
推荐答案
我需要将所有参数保存到向量或某个
i need to save all arguments to a vector or something
您可以使用向量的范围构造函数,并传递适当的迭代器: / p>
You can use the range constructor of the vector and pass appropriate iterators:
std::vector<std::string> arguments(argv + 1, argv + argc);
不是100%确定如果这是你问的。如果没有,请澄清。
Not 100% sure if that's what you were asking. If not, clarify.
这篇关于将argv保存到向量或字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文