【发布时间】:2014-11-25 19:49:27
【问题描述】:
我正在尝试编写一个 C++ 程序,该程序需要一个 5 个字符长的字符串,然后按以下顺序打印出具有新排列的字符串:第 1 个字符、第 3 个字符、第 5 个字符、第 2 个字符、第 4 个字符。我的代码如下:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string key;
string p10;
cout << "Enter the five characters long string: ";
cin >> key;
p10 = key[0] + key[2] + key[4] + key[1] + key[3];
cout << p10 << endl;’
system(“pause”);
return 0;
}
每次运行时,输出 (p10) 都是一个随机的希腊字母。
请帮忙!
【问题讨论】:
-
string key;不应该是char[] key;吗?
标签: c++ string permutation