簡體   English   中英

boost :: trim std :: vector中的每個字符串<std::string>

[英]boost::trim each string in std::vector<std::string>

我目前很難找到修正std :: vector中每個字符串的正確語法。

我試過了

std::vector<std::string> v;
std::for_each(v.begin(), v.end(), &boost::trim);

它在MSVC7.1中給了我以下錯誤消息。

錯誤C2784:'_ Fn1 std :: for_each(_InIt,_InIt,_Fn1)':無法使用[_Ty = std :: string]從'std :: vector <_Ty> :: iterator'中推斷'T1'的模板參數:看到'std :: for_each'的聲明

錯誤C2896:'_ Fn1 std :: for_each(_InIt,_InIt,_Fn1)':不能使用函數模板'void boost :: algorithm :: trim(SequenceT&,const std :: locale&)'作為函數參數:參見聲明'boost :: algorithm :: trim'

如果我明確地給出了模板參數trims,那么編譯器無法找到第二個參數,雖然它默認設置。

std::for_each(v.begin(), v.end(), &boost::trim<std::string>);

錯誤C2198:'void(__ cdecl *)(std :: string&,const std :: locale&)':通過指針到函數調用的參數太少

我想知道如何為v每個元素調用trim的正確語法。

您還需要綁定trim的第二個參數(語言環境):

std::vector<std::string> v;
std::for_each(v.begin(), v.end(), 
              boost::bind(&boost::trim<std::string>,
                          _1, std::locale() ));

暫無
暫無

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

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