0

Output string backward

How to output string variables backwards

20th Dec 2020, 3:26 PM
Hakam
7 odpowiedzi
+ 3
show your attempts first
20th Dec 2020, 3:36 PM
ÃKR
ÃKR - avatar
+ 1
#include <iostream> #include <string> using namespace std; int main () { string word; cout << "Enter the word you want it to be written backwards" ; cin >> word; // this is where i stopped return 0; }
20th Dec 2020, 4:02 PM
Hakam
+ 1
Hakam This can't be your efforts. Any new learner can do this.
20th Dec 2020, 4:16 PM
A͢J
A͢J - avatar
+ 1
string speakBackwards(string str) { string s = ""; int counter = 0; for (int i = static_cast<int>(str.size()) - 1; i >= 0; i--) { s += str[i]; str += s[counter++]; } return s; } Usage: word = speakBackwards(word);
20th Dec 2020, 10:13 PM
Erix
Erix - avatar
0
Your attempt?
20th Dec 2020, 3:36 PM
Abdumalik Khojimirzaev
0
Believe it or not, this is the attempt!. I saw someone's comment that she made a program to print string backwards, and that's what i am trying to discover.
20th Dec 2020, 4:22 PM
Hakam