日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

问题:出现在哪个地方?关于map的搜索问题

發(fā)布時(shí)間:2024/4/18 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 问题:出现在哪个地方?关于map的搜索问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include <iostream> #include <string> #include <map> #include <set> using namespace std; const string &trans(map<string,string> &m,const string &s){//問題在下面的(auto pos = m.find(s) != m.end())把pos定義放在外面就可以了if((auto pos = m.find(s)) != m.end()){return s;}elsereturn "good"; } int main() { map<string,string> m;return 0; } //g++編譯結(jié)果 r@r:~/coml/c++/11/11.3/11.3.6/myself_word_transform$ g++ test.cc -o 123 test.cc: In function ‘const string& trans(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >&, const string&)’: test.cc:8:10: error: expected primary-expression before ‘a(chǎn)uto’8 | if((auto pos = m.find(s)) != m.end())| ^~~~ test.cc:8:10: error: expected ‘)’ before ‘a(chǎn)uto’8 | if((auto pos = m.find(s)) != m.end())| ~^~~~| ) test.cc:12:3: error: expected ‘)’ before ‘else’12 | }| ^| )13 | else| ~~~~ test.cc:8:8: note: to match this ‘(’8 | if((auto pos = m.find(s)) != m.end())| ^ test.cc:17:3: warning: no return statement in function returning non-void [-Wreturn-type]17 | }| ^

問題已經(jīng)解決;代碼中顯示的,把pos定義放在外面就可以了

總結(jié):if語句中,括號(hào)內(nèi)可以有賦值語句,但是不能有定義語句。

總結(jié)

以上是生活随笔為你收集整理的问题:出现在哪个地方?关于map的搜索问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。