【发布时间】:2011-06-29 13:18:00
【问题描述】:
我的 main 函数包含一个我想弄乱的字符串。我找到了一段代码,它传入 char* 并在完成时返回 0。我已按照代码提供者的说明简单地传入您想要混淆的字符串。
#include <iostream>
#include <string.h>
#include <time.h>
using namespace std;
int scrambleString(char* str)
{
int x = strlen(str);
srand(time(NULL));
for(int y = x; y >=0; y--)
{
swap(str[rand()%x],str[y-1]);
}
return 0;
}
当我这样做时,我收到一个错误 "no suitable conversion function "std::string" to "char*" exists。
我也尝试过传入const char*,但这不允许我访问和更改单词。
【问题讨论】: