低於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
你能更詳細地描述你想做什麼嗎?例如。你試圖讓字符串包含數字的文本表示,或其他東西 –