2012-02-03 183 views
1

我有一個函數,我希望能夠返回打印輸出,然後我可以在頁面上打印輸出。我將如何返回這兩個if語句中輸出的字符串?從函數返回多個字符串

std::vector<std::string> el; 
     split(el,message,boost::is_any_of("\n")); 
     std::string a (""); 

      for(int i = 0; i < el.size(); i++) 
      { 
       if(el[i].substr(0,3) == ".X/") 
       { 
        DCS_LOG_DEBUG("--------------- Validating .X/ ---------------") 
        std::string str = el[i].substr(3); 
        std::vector<std::string>st; 
        split(st,str,boost::is_any_of("/")); 
        boost::regex const string_matcher(splitMask[0]); 
        if(boost::regex_match(st[0],string_matcher)) 
        { 
         a = "Correct Security Instruction"; 

        } 
        else 
        { 
         a = "Incorrect Security Instruction" 
        } 

        boost::regex const string_matcher1(splitMask[1]); 
        if(boost::regex_match(st[1],string_matcher1)) 
        { 
        a = "Correct Security screening result" 
        } 
        else 
        { 
         a = "Incorrect Security screening result" 
        } 


        return a; 

       } 

      } 

心存感激任何幫助:)

回答

0

您可以將字符串推送到作爲參考傳遞給該函數的std :: vector中,然後在返回時迭代該向量。

3

可以返回一個字符串std::pair,例如。

3

定義一個具有兩個適當命名的字符串成員的類並返回該類的一個實例。

然後,開始思考哪些方法或其他數據對該類有用。

0

我會返回std::pairbool值(其中一個表示指令是否正確,另一個表示篩選結果是否正確),並讓調用代碼解釋結果。