【发布时间】:2017-08-11 12:59:22
【问题描述】:
我一直在尝试将向量传递给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_st,你的意思应该是string::c_str() -
string c = "Taskkill /F /IM " (vl.begin(), vl.end())));应该做什么? -
顺便说一句,要么我遗漏了某些东西,要么您的错误消息与代码不匹配。我怀疑在你的真实代码中你有
c.c_str在这里你有c.c_st -
@JohannesKhazaal 这不是连接字符串向量的方式。为此,请参阅:stackoverflow.com/questions/1985978/…