我需要从两个字符串和一个整数中收集一个字符串,例如:'unzip -P 123456 file.zip'。我的代码:
#include <iostream>
using namespace std;
int main () {
string out;
string s1 = "unzip -P ";
string s2 = " file.zip";
int pass = 123456;
out = s1 << to_string(pass) << s2;
cout << out << endl;
return 0;
};
编译时有两个错误:
/usr/include/c++/9/ostream:691:5: ошибка: нет имени типа «type» в «struct std::enable_if<false, void>»
myfile.cpp:9:14: ошибка: no match for «operator<<» (operand types are «std::string» {aka «std::__cxx11::basic_string<char>»} and «std::string» {aka «std::__cxx11::basic_string<char>»})
为什么会这样?我折线错了吗?还有其他方法吗?提前致谢!
你的代码:
更正的代码:
错误: 1. 你没有包含
<string>
. 它旨在处理 C++ 中的字符串。选项编号 1
选项编号 2
选项 3