c++ - c++中bash(system-> wget)命令的问题

标签 c++ bash

这是我的代码:

string line;
ifstream toOpen;
toOpen.open("allfiles.txt", ios::in);
int fileCounter=0;

if(toOpen.is_open()){
    while(!toOpen.eof()){
        getline(toOpen,line);
        string dl = "wget -q -E -O  superman/" + href[0] + " " + line;
        //cout << dl << endl;
        fileCounter++;
        system(dl);
    }

    toOpen.close();
}

其中 allfiles.txt(内容):

http://www.xxx.com/index1.html
http://www.xxx.com/index2.html

其中 href[] 值类似于:{index1.html, index2.html, index3.html ...}

我的错误信息:

file.cpp:XX: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int system(const char*)’

最佳答案

函数“system”接受一个“const char *”作为参数,但你给了它一个 std::string。尝试

system(dl.c_str());

关于c++ - c++中bash(system-> wget)命令的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4279647/

相关文章:

c# - 是否有编译为机器代码的 C C++ C# 编译器

c++ - 迭代器不可取消引用堆栈(表达式树)和循环无法正常工作

为性能测试生成大量 ssl/tls 连接的 Bash 脚本

python - 存储 os.system 或 os.popen 的值

c++ - 在C++中使用nan初始化内存以进行调试

c++ - typedef 和宏有什么区别?

c++ - 将对象 vector 序列化为 std::string 以便与 MPI 一起使用

linux - 基本 bash 重定向

bash - Bash 中输出错误的多个条件

bash - 意外标记附近出现语法错误 `<'