将 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
您可以使用向量的范围构造函数并传递适当的迭代器:
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屋!
查看全文