Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C++;_C++ - Fatal编程技术网

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