C++ 如何在C++;
最近我开发了一个程序,在其中我必须调用C++ 如何在C++;,c++,C++,最近我开发了一个程序,在其中我必须调用system()它接受一个常量字符*。我需要在这个调用中使用字符串数组。下面是一些示例代码 #include <iostream> #include <windows.h> #include <string> using namespace std; int main() { string stackoverflow[5] = {"a", "b", "c", "d", "e"}; int i = 0;
system()代码>它接受一个常量字符*
。我需要在这个调用中使用字符串数组。下面是一些示例代码
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
string stackoverflow[5] = {"a", "b", "c", "d", "e"};
int i = 0;
while(i <= 5)
{
system("wget -O" + stackoverflow[i] + "\"www.google.com\"");
i++;
}
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串stackoverflow[5]={“a”、“b”、“c”、“d”、“e”};
int i=0;
while(i首先创建一个组合字符串,然后使用std::string.c_str()
函数
std::string combined = "wget -O" + stackoverflow[i] + "\"www.google.com\"";
system(combined.c_str());
试试这个:
int main()
{
string stackoverflow[5] = {"1","2","3","4","5"};
int i = 0;
while (i < 5)
{
string args = "wget -O" + stackoverflow[i] + "\"www.google.com\"";
system(args.c_str());
i++;
}
}
intmain()
{
字符串stackoverflow[5]={“1”、“2”、“3”、“4”、“5”};
int i=0;
而(i<5)
{
string args=“wget-O”+stackoverflow[i]+“\”www.google.com\”;
系统(args.c_str());
i++;
}
}
const char b=stackoverflow[i].c_str()
您正在将指向char的指针分配给char,而不是指针解析!(等待计时器正式接受。)在(i