gpt-4-0613· OpenAI
Arena Human Preference 55K
Write a code that reverses a string in C++.
- User
Write a code that reverses a string in C++.
- Assistant
Sure, here is a simple C++ code snippet that reverses a string:
#include <iostream> #include<string> #include<algorithm> int main() { std::string str; // Input string std::cout << "Enter a string: "; std::getline(std::cin, str); // Reverse the string std::reverse(str.begin(), str.end()); // Print the reversed string std::cout << "Reversed string: " << str << std::endl; return 0; }This program uses the
std::reversefunction from the<algorithm>library to reverse the string. It is a built-in function in C++ STL that directly reverses the string.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.