合并排序 std:string 中的字符
Merge sort the character in a std:string
所以我正在尝试合并对字符串的字母进行排序,以便它们按顺序排列。大写并不重要,因为家庭作业不需要它。由于某种原因,我无法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];
}
任何帮助,不胜感激。
>split
是一个string*
,这意味着split[some]
不会从字符串中获取字符,而是从字符串数组中获取字符串。
解决此问题的最简单方法是将函数定义更改为具有string &split
,如果要修改变量。
相关文章:
- 如何将带有十六进制值的 std::string 转换为 std::vector<无符号字符>
- "std::string"是否将其字符作为签名字符在内部存储?
- 无法<string>从"常量字符 []"转换为<类名>
- 如何在 c++ 中将向量转换为<string>常量字符* const*?
- C++ 从 std::string 中删除所有非数字字符
- 使用 .data() 将字符数组转换为 std::string 不会转换整个数组
- 有没有办法搜索向量的元素,<String>然后检查它是否包含特定的字符,如果它确实打印了它
- 将单个字符转换为 std::string 前缀 \x01
- 将utf16宽std::wstring转换为utf8窄std::string以获得罕见字符时出现问题
- 为什么一个表达式中的 std::string 连接给出的结果与逐个字符不同的结果?
- 将 std::string 转换为具有特殊字符的 FString (TCHAR / wstring)
- 如何互换使用字符* 和 std::string?
- 从 std::string 中删除特定的连续字符重复
- 如果必须包含西里尔字符,如何将 char* 转换为 std::string?
- 将空填充但不以空结尾的固定长度字符数组转换为 std::string 的最佳方法
- 如何在矢量"[i]"中插入*字符<string>?[C++]
- Qt UTF-8 文件到 std::string 添加额外的字符
- 如何从字符*转换为"WTF::String"?
- 使用STD :: String和字符数组之间的选择
- 字符 * 和 const_cast<字符*>(string.c_str())有什么区别