In: Computer Science
Write a program that uses a for loop output a string in reverse printing it character by character. C++ Program
Example:
"Enter some text:"
this is a test
"your text in reverse is:"
tset a si siht
Please note that you can find the length of the string by using the length function:
string str = "hello"
cout << str.length();
Also you can et a character in a string by providing an index to the function
string str = "hello"
cout << str.at(2) << endl;
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please rate the answer.
Thank You !
===========================================================================
#include <iostream>
#include <string>
using namespace std;
int main(){
string text;
cout<<"Enter some text:\n";
getline(cin,text,'\n');
int length = text.length();
for(int i=length-1; i>=0; i--)
cout<<text.at(i);
cout<<endl;
}
==================================================================