C++ Printing a string in reverse using a for loop

前端 未结 6 1619
别跟我提以往
别跟我提以往 2021-01-25 12:13

I have a program that prints out the characters of a string using a for-loop. It must also print the same characters in reverse, which is where I\'m having problems. Can someone

6条回答
  •  一生所求
    2021-01-25 12:24

    You need to assign i initially to the length minus one, or the last index value in the array.

    for(i = myAnimal.length()-1; i >= 0; i--){
        cout << myAnimal.at(i) << endl;
    }
    

提交回复
热议问题