簡體   English   中英

在C ++中,得到一個錯誤說“std :: string {aka std :: basic_string <char> }&#39;不是從&#39;const __gnu_cxx :: __ normal_iterator &lt;_IteratorL,_Container&gt;派生的

[英]in C++, get an error says “std::string {aka std::basic_string<char>}' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>”

int webServerPort = -1;    

void configure(std::string responseFile, callback_function call_back, std::string urlRegex = NULL) {
        std::string url = "http://0.0.0.0:" + webServerPort + "fake_settings/?file=" + responseFile;
        if(urlRegex != NULL) {  // GOT ERROR HERE
            url += "&pattern=" + urlRegex;
        }

得到一個錯誤,實際上它不被稱為“錯誤”而是“注意”

錯誤說:注意:'std :: string {aka std :: basic_string}'不是從'const __gnu_cxx :: __ normal_iterator <_IteratorL,_Container>'派生的

有人對此有所了解嗎?

謝謝

兩件事:首先,你將urlRegex默認為NULL 你的意思是空字符串嗎? 如果是這樣,請不要打擾,因為這是字符串的默認值。 然后,當您檢查urlRegex是否為NULL時,請執行以下操作:

if(!urlRegex.empty()) { // ...

其次,您正在嘗試將webServerPort (一個int)添加到std :: string上。 那不合法。 如果你真的想這樣做,那么解決它的方法是:

std::ostringstream ss;
ss << "http://0.0.0.0:" << webServerPort << "fake_settings/?file=" << responseFile;
std::string url = ss.str();

暫無
暫無

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

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