Write a program that accepts a string input from the user andreverses the conten
ID: 3610345 • Letter: W
Question
Write a program that accepts a string input from the user andreverses the contents of the string. Your program should work byusing two pointers. The “head” pointer should be set tothe address of the first charter in the string and“tail” pointer should set to the address of the lastcharter in the string.[code]
#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 != '') {
cstr[i] = *tail;
*tail--;
*head++;
i++;
}
cout << cstr;
cout <<" ";
return 0;
}
I am getting a linking error stating buffer is too small how to fixthis
Thanks