gpt-4-1106-preview· 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
Certainly! Below is a simple example of a C++ program that reverses a string. This program uses the
<algorithm>header'sreversefunction to reverse the string:#include <iostream> #include <algorithm> #include <string> int main() { std::string str; std::cout << "Enter a string to reverse: "; std::getline(std::cin, str); std::reverse(str.begin(), str.end()); std::cout << "Reversed string: " << str << std::endl; return 0; }When you run this program, it will prompt you to enter a string. After you enter the string and press Enter, it will display the reversed string.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.