小编Ali*_*yer的帖子

`std :: swap`不能按预期的那样在字符串处理中工作

我试图通过交换两个连续的字母来进行基本的字符串加密。而且它并没有真正按照我的预期工作。

#include <iostream>
#include <string.h>
#include <algorithm>

int main() 
{
    std::string str = "This is a simple string.";
    for (int i = 0; i <= str.length(); i++) {
        std::swap(str[i], str[i + 1]);
    }
    std::cout << str;
    std::cin.get();
}
Run Code Online (Sandbox Code Playgroud)

我实际上想交换两个附近的字母,所以它看起来像加密的。当前结果是

his is a simple string.
Run Code Online (Sandbox Code Playgroud)

c++ encryption algorithm loops stdstring

3
推荐指数
1
解决办法
104
查看次数

标签 统计

algorithm ×1

c++ ×1

encryption ×1

loops ×1

stdstring ×1