小编Dan*_*min的帖子

C ++反转字符串

我试图在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)

c++ string

0
推荐指数
2
解决办法
5825
查看次数

标签 统计

c++ ×1

string ×1