【发布时间】:2020-06-04 12:42:57
【问题描述】:
我创建类型链表并从用户那里获取字符。 这是类定义。
template <class nodeT>
struct nodeSLL
{
int data; //Data inside the node
nodeSLL* link; //Address next node
};
char itemC;
这是一个 main()
singlyLinkedList<char> listCSLL; //Creating linked list
cout << "Create Char Single Linked List: "
<< "\nCTRL+Z for exit!" << endl;
cin >> itemC;
while (!cin.eof())
{
listCSLL.insertLast(itemC);
cin >> itemC;
}
listCSLL.printSLL();
但我的打印函数打印字符的 ASCII 十进制表示
template <class nodeT>
void singlyLinkedList<nodeT>::printSLL()
{
nodeSLL<nodeT>* move;
move = head;
while (move != NULL)
{
cout << move->data << " ";
move = move->link;
}
}
我的程序可以创建 int 或 char 列表,用于打印 int 没问题,但 char 列表打印 ascii 十进制格式
【问题讨论】:
-
请包括您正在使用的类的定义 -
nodeSLL<nodeT>::data的类型可能与此处相关。通常,您应该将问题简化为mcve 以使其更清晰,这样您通常会自己找到解决方案。 -
现在可以了吗? @hnefatl
-
你应该使用
nodeT data;模板化而不是int data; -
感谢您帮助它现在工作。 @Wander3r 我无法回答标记解决问题
标签: c++ linked-list