Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

sorting vector of vector of strings in C++

I am having trouble to figure out, how to sort a vector of vector of strings, here is the testing code.


#include &ltiostream>
#include &ltvector>
#include &ltboost/algorithm/string.hpp>

int main(int argc, char** argv) {
  std::vector &ltstd::vector &ltstd::string> > data_var;
  std::vector &ltstd::string> temp;

  std::string str1 = "1,hello3,temp2";
  std::string str2 = "2,hello2,temp1";
  std::string str3 = "3,hello1,temp3";

  boost::split(temp, str1, boost::is_any_of(","));
  data_var.push_back(temp);
  boost::split(temp, str2, boost::is_any_of(","));
  data_var.push_back(temp);
  boost::split(temp, str3, boost::is_any_of(","));
  data_var.push_back(temp);

  // sorting code here...
}

Thanks in advance...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Alright: new -simpler- answer, having learned that vectors are comparable:

//sorting code here...
std::sort(data_var.begin(), data_var.end(), std::greater<std::vector<std::string>>());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...