write the best program in c++
- User
write the best program in c++
Assistant
Here's a simple yet elegant C++ program that demonstrates good practices:
#include <iostream> #include <string> #include <vector> #include <algorithm> // A program that takes a list of names, sorts them, and greets each person int main() { std::cout << "Enter names (one per line, type 'done' when finished):\n"; std::vector<std::string> names; std::string input; // Collect names while (std::getline(std::cin, input) && input != "done") { if (!input.empty()) { names.push_back(input); } } // Sort names alphabetically std::sort(names.begin(), names.end()); // Greet each person std::cout << "\nGreetings to everyone:\n"; for (const auto& name : names) { std::cout << "Hello, " << name << "! Welcome to our program.\n"; } // Summary std::cout << "\nGreeted " << names.size() << " people today.\n"; return 0; }Would you like me to explain or break down this code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.