【问题标题】:How to resolve " invalid operands of types 'const char [ ]' and 'const char*' to binary 'operator+' "如何将“'const char []'和'const char*'类型的无效操作数解析为二进制'operator+'”
【发布时间】:2014-02-22 17:11:06
【问题描述】:

我使用 Qt Creator 和这段代码:

string execpath = "";
execpath += (QCoreApplication::applicationDirPath()).toStdString();
WinExec("ffmpeg -f dshow -t 32 -i audio=\"virtual-audio-capturer\" -y "+(execpath.c_str())+"\\sound.mp3", SW_HIDE); // Loopback captured in sound.mp3

在第 3 行生成此问题:

'const char [60]' 和 'const char*' 类型的无效操作数 二进制'运算符+'

如何解决?

【问题讨论】:

  • 你不能用 + 操作符把 C 风格的字符串加在一起
  • 先连接字符串,然后然后在连接的std::string上调用.c_str()

标签: c++ qt c-str


【解决方案1】:

你会想要这样的东西:

execpath += (QCoreApplication::applicationDirPath()).toStdString();
std::string cmd = "ffmpeg -f dshow -t 32 -i audio=\"virtual-audio-capturer\" -y "
WinExec((cmd +execpath +"\\sound.mp3").c_str(), SW_HIDE);

【讨论】:

  • execpath 是我在代码中经常使用的变量,但我猜你是对的
  • 这有效:WinExec(string("ffmpeg -f dshow -t 32 -i audio=\"virtual-audio-capturer\" -y "+execpath+"\\sound.mp3")。 c_str(), SW_HIDE); // 在 sound.mp3 中捕获的环回
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
  • 2014-09-30
  • 2020-06-23
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多