CodersSC
CodersSC

Reputation: 710

returning multiple strings from a function

I have a function where i want to be able return what is printed out so then i can print the output on the page. How will i return both of the string which are outputted within both of those if statements ?

 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;

              }

          }

Thankfull for any help :)

Upvotes: 1

Views: 895

Answers (4)

Karl Knechtel
Karl Knechtel

Reputation: 61478

I would return a std::pair of bool values (one to indicate if the instruction is correct, and one to indicate if the screening result is correct), and let the calling code interpret the results.

Upvotes: 0

Alan Stokes
Alan Stokes

Reputation: 18964

Define a class with two appropriately-named string members and return an instance of that.

Then, start to think about what methods or other data would be useful to have on that class.

Upvotes: 3

perreal
perreal

Reputation: 97918

You can push the strings in a std::vector that is passed to the function as a reference and later iterate over the vector upon return.

Upvotes: 0

unwind
unwind

Reputation: 399713

You can return an std::pair of strings, for instance.

Upvotes: 3

Related Questions