[英]Passing “vector<string>” as function argument and I get an error
I've furthered in the realization of my save function and got the idea of passing my arguments as "vector" (because they are) instead of "string" which gives this: 我进一步实现了save函数的实现,并想到了将参数传递为“ vector”(因为它们是)而不是“ string”,从而实现了:
void saveFunction(ofstream& save, vector<string> site, vector<string> url, vector<string> username, vector<string> password)
{
save << site;
save << url;
save << username;
save << password;
}
which gives this error: 这给出了这个错误:
error: no match for 'operator<<' (operand types are 'std::ofstream' {aka 'std::basic_ofstream<char>'} and 'std::vector<std::__cxx11::basic_string<char> >')
ofstream
does not have an overloaded <<
operator for a std::vector
, so you need to roll one yourself, for example ofstream
的std::vector
没有重载<<
运算符,因此您需要自己滚动一个,例如
for (auto&& s : username){
save << s;
}
although your reasons for using a std::vector
might be questionable. 尽管您使用std::vector
原因可能令人怀疑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.