#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
stack<char> temp;
string a;
int i = 0;
cin >> a;
while (a[i] != '\0') {
temp.push(a[i]);
i++;
}
while (!temp.empty()) {
cout << temp.top();
temp.pop();
}
cout << endl;
system("pause");
return 0;
}
本文介绍了一种利用C++标准库中的堆栈数据结构来实现字符串反转的方法。通过逐字符读取输入字符串并压入堆栈,再依次弹出堆栈中的元素,最终得到反转后的字符串。该程序简洁高效,适用于需要字符串反转的各种场景。
6992

被折叠的 条评论
为什么被折叠?



