我试图在revStr.at(j)= str.at(size);下面的c代码行中反转一个字符串;
不会更改revStr中的任何元素。
还有另一种不用任何库就可以做到的方法。
#include <iostream>
#include<sstream>
#include <iterator>
using namespace std;
int main() {
ostringstream d;
long long c = 123456789;
d << c;
//cout << c << endl;
string str = d.str();
//cout << str.at(0) << endl;
int size = str.size() - 1;
//cout << size << endl;
ostringstream e;
e << str;
string revStr = e.str();
for (int i = size; size==0; size--) {
//cout << str.at(size);
int j = 0;
revStr.at(j) = str.at(size);
j++;
} // …Run Code Online (Sandbox Code Playgroud)