注意:

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++输入字符串的多种方法总结

相关文章:

  • 2021-08-15
  • 2021-07-19
猜你喜欢
  • 2021-04-16
  • 2022-12-23
  • 2021-04-26
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案