Hey all I am new to c++ and I am working on a simple project which takes an inputted string and outputs the string in reverse. I coded the program using what I remembered from programming classes I took years ago however I keep getting a warning for using strcpy and it will not compile on the command prompt and I am not exactly sure the alternative way. Please help. Here is the code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string reverse;
char *head, *tail, *cstr, temp;
int i = 0;
cout << "Please enter a string: " << endl;
cin >> reverse;
cstr = new char[reverse.size() + 1];
strcpy(cstr, reverse.c_str());
head = &cstr[0];
tail = &cstr[reverse.size() - 1];
cout << "The string inverted is: " << endl;
while (head <= tail) {
temp = cstr[i];
cstr[i] = *tail;
*tail = temp;
*tail--;
*head++;
i++;
}
cout << cstr;
cout << "\n";
return 0;
}