c++ - Linked List Print() 函数打印字符的ASCII码
问题描述
我创建类型链表并从用户那里获取字符。这是类定义。
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 十进制格式
解决方案
而不是
int data;
您应该通过将 nodeSLL 更改为
nodeT data;
If not 来模板化 nodeSLL,无论是传递int
还是char
任何其他数据类型仍会导致打印int
。
如果没有,传递模板根本不会影响struct nodeSLL
。
推荐阅读
- r - How can I get correct date format for ambiguous temperature data?
- tensorflow - Tensorflow Tensor out of CSV has no size?
- django - 如何在 Chrome/Firefox 中仅强制重新加载某些源
- c# - Grid is getting smaller after pressing "AddLexemesFromFolder" button
- javascript - jquery toggle between ul li many to many child
- scala - Can't call map method in function with cats library
- objective-c - NSUserDefaults 的替代方案来保存 Bool?
- parse-server - 我们应该为 Parse Server 使用什么云服务
- lazarus - 使用带有 Lazarus/FreePascal 的 TIniFile-ReadSection 的 ini-file-comments
- linux - stat command with formatted string argument in Linux