反转读入的任意字符串

注意:

getline()函数会把最后一个字符(回车键'/n')读入,但在存区时只会保存空字符('/0')

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str;
    getline(cin,str);
    int len = str.size();
    for(int i=len-1;i>=1;i--){
        cout<<str[i];
    }
}

参考:c++输入字符串的多种方法总结

posted @ 2021-02-11 02:23  TR_Goldfish  阅读(50)  评论(0编辑  收藏  举报