Write a segment of C code that given a string inStr will cre
Write a segment of C++ code that, given a string inStr, will create a new string outStr such that outStr is the reverse of intStr. Use a loop. For example, if the given inStr is “Hello” then your code should create outStr equal to “olleH”.
(This is only an example; your code must be general and must work for any given input string inStr.)
Hint: Use a loop to extract the characters from inStr, one at a time, and use them to build up by concatenating them using the + operator.
Write a segment of C++ code that, given a string inStr, will create a new string outStr such that outStr is the reverse of intStr. Use a loop. For example, if the given i
Solution
include<iostream>
#include<conio.h>
#include<string>
int main()
{
std::string arr;
int i =0,len,a;
std::cout<<\"Enter the String: \ \";
getline (std::cin, arr);
std::cout<<\"\ \";
std::cout<<\"String You Have Entered Is:\\t\"<<arr;
int j=arr.length()-1;
while(i<j)
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j--;
}
std::cout<<\"\ \";
std::cout<<\"Reverse of the String is :\"<<arr;
return 0;
}
