低于check
是字符串,而temp1->data
是整数。我想将temp1->data
插入check
。所以我输入int
到const char*
。这使代码warning : cast to pointer from integer of different size [-Wint-to-pointer-cast]
如何在C++中使用插入函数将整数插入到字符串中?
部分:
temp1 = head;
std::string check;
check = "";
int i = 0;
while(temp1 != NULL)
{
check.insert(i, (const char*)temp1->data);// here is the warning
temp1 = temp1->next;
++i;
}
我想知道我有使用插入功能插入整数(temp1->data
)转换为字符串(check
)什么其他的选择,什么是警告的实际效果[-Wint-to-pointer-cast]在我的代码上。
点:
- 数据是整数,其次是指向节点
- 我想要实现的功能,以检查是否含有单位数链表是回文与否。是的,我知道其他方法,但我只是想通过这种方法来实现。
- 这里我想将链接列表的所有数据存储到一个字符串中,并直接检查字符串是否是回文。
此问题看起来可能与this重复。但它不是,我在这里明确要求使用包含在字符串类中的插入函数将整数插入到字符串中。
PS:使用std::to_string(temp1->data) gives me error ‘to_string’ is not a member of ‘std’
。
你想做什么?你是否愿意将一个整数插入到一个字符串或其他东西? – surajsn
数据的性质是什么,以及为什么要尝试这样做? – StoryTeller
你能更详细地描述你想做什么吗?例如。你试图让字符串包含数字的文本表示,或其他东西 –