int main()
try
{
    vector<string> string_v;
    string_v.push_back("first");
    string_v.push_back("second");
    string_v.push_back("third");
    string_v.push_back("fourth");
    string_v.push_back("fifth");
    string_v.push_back("sixth");
    string_v.push_back("seventh");
    cout << "Vector of strings:\n";
    print(string_v);
    vector<int> lengths = string_lengths(string_v);
    cout << "Vector of lengths:\n";
    print(lengths);
    cout << "Longest string: " << longest_string(string_v) << endl;
    cout << "Shortest string: " << shortest_string(string_v) << endl;
    cout << "Lexicographically first string: " << alpha_first_string(string_v) << endl;
    cout << "Lexicographically last string: " << alpha_last_string(string_v) << endl;
}
catch (exception& e) {
    cerr << "exception: " << e.what() << endl;
}
catch (...) {
    cerr << "exception\n";
}
예제 #2
0
int main()
{
  std::vector<std::string> words;

  std::string word;
  std::string line;
  std::getline(std::cin,line);
  std::istringstream iss(line);
  while(iss >> word)
    {
      words.push_back(word);
    }

  count_chars(words);
  std::cout << "longest: " << longest_string(words) << '\n';
  std::cout << "shortest: " << shortest_string(words) << '\n';
  std::cout << "lexico_first: " << lexico_first(words) << '\n';
  std::cout << "lexico_last: " << lexico_last(words) << '\n';
  std::cout << "finished \n";
  return 0;
}