Write a program that accepts a string input from the user and reverses the contents of the string. Your program should work by using two pointers. The “head” pointer should be set to the address of the first charter in the string and “tail” pointer should set to the address of the last charter in the string.
#include<iostream>
#include<string>
using namespace std;
int main() {
string str;
char *head, *tail, *cstr;
int i = 0;
cout << "Enter a string: ";
getline(cin, str);
cstr = new char[str.size() + 1];
strcpy_s(cstr,sizeof(cstr), str.c_str());
head = &cstr[0];
tail = &cstr[str.size() - 1];
cout << "String inverted is: ";
while (*head != '\0') {
cstr[i] = *tail;
*tail--;
*head++;
i++;
}
cout << cstr;
cout <<"\n";
return 0;
}
I am getting a linking error stating buffer is too small how to fix this
Thanks