簡體   English   中英

傳遞“矢量 <string> ”作為函數參數,但出現錯誤

[英]Passing “vector<string>” as function argument and I get an error

我進一步實現了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;

}

這給出了這個錯誤:

error: no match for 'operator<<' (operand types are 'std::ofstream' {aka 'std::basic_ofstream<char>'} and 'std::vector<std::__cxx11::basic_string<char> >')

ofstreamstd::vector沒有重載<<運算符,因此您需要自己滾動一個,例如

for (auto&& s : username){
    save << s;
}

盡管您使用std::vector原因可能令人懷疑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM