我想通過使用堆棧來反轉char *。C++分配char值(通過使用堆棧彈出)char *
stack<char> scrabble;
char* str = "apple";
while(*str)
{
scrabble.push(*str);
str++;
count++;
}
while(!scrabble.empty())
{
// *str = scrabble.top();
// str++;
scrabble.pop();
}
在第二while循環,我不知道如何給每個字符從堆棧的頂部爲char *海峽分配。
你不應該只是遍歷它向後並將其複製到一個新的緩衝區? – Cebtenzzre