所以我试图合并排序字符串的字母,以便它们按顺序排列。资本化并不重要,因为家庭作业不需要它。出于某种原因,我无法获得templet[index] = split[leftfirst]
。我得到一个“没有合适的转换函数从std :: string到char存在”。继承我的合并功能
void merge(string *split, int leftfirst, int leftlast, int rightfirst, int rightlast)
{
string templet;
int index = leftfirst;
int savefirst = leftfirst;
while ((leftfirst <= leftlast) && (rightfirst <= rightlast))
{
if (split[leftfirst] < split[rightfirst])
{
templet[index] = split[leftfirst];
leftfirst++;
}
else
{
templet[index] = split[rightfirst];
rightfirst++;
}
index++;
}
while (leftfirst <= leftlast)
{
templet[index] = split[leftfirst];
leftfirst++;
index++;
}
while (rightfirst <= rightlast)
{
templet[index] = split[rightfirst];
rightfirst++;
index++;
}
for (index = savefirst; index <= rightlast; index++)
split[index] = templet[index];
}
感谢任何帮助。
答案 0 :(得分:1)
split
是string*
,这意味着split[some]
不会从字符串中获取字符,而是从字符串数组中获取字符串。
如果要修改变量,最简单的解决方法是将函数定义更改为string &split
。