如何将字符串和向量传递到system()中?
How to pass string and vector into system()?
我试图将向量传递到system()
函数中。 我读过以前关于这个话题的问题,但我空手而归。
class aloha
{
private:
string str;
public:
void Caller() {
std::string line;
std::vector<string>vl;
std::ifstream file("data.txt");
while (file >> line) {
vl.push_back(line);
std::string c = "Taskkill /F /IM " (vl.begin(), vl.end())));
system(c.c_str()));
}
}
};
我遇到了以下错误,这让我发疯了:
||=== Build: Debug in Instruction (compiler: GNU GCC Compiler) ===| error: expression cannot be used as a function error: cannot convert 'std::basic_string<_CharT, _Traits, _Alloc>::c_str<char, std::char_traits<char>, std::allocator<char> >' from type 'const char* (std::basic_string<char>::)() const' to type 'const char*'|`
提前感谢,如果你们需要更多信息/示例代码,我会放更多。
对不起,我是 c++ 的新手
下面的行是要查看的行。
string c = "Taskkill /F /IM " (vl.begin(), vl.end())));
您可以将字符串与 std::append 连接起来 http://www.cplusplus.com/reference/string/string/append/
您需要在 for 循环中执行此操作,一次附加一个向量的每个项目。但是,由于示例中的向量仅包含一个元素,因此上面的代码并不完全需要它。一旦你有了你想要的字符串,你可以把它传递给system((。