为什么我的程序在运行时间后输出%符号?

时间:2014-04-09 15:42:32

标签: c++ cout

我正在尝试构建自己的二叉搜索树实现。我几乎所有工作,我想编写一个递归方法,按顺序打印树中的值。我使用了以下内容:

void innerPrint(Node * node) {
    if (node->getLeft() != NULL) innerPrint(node->getLeft());
    cout << node->getValue() << " ";
    if (node->getRight() != NULL) innerPrint(node->getRight());
}

这是一个私有函数,然后实际的print函数只用我的RootNode作为初始输入来调用它。以下是我的输出。我的问题是,这个百分号出现的原因是什么?我过去曾遇到过类似的问题,需要打印的所有内容都已完成,但最终还会出现这个问题。

但我无法弄清楚为什么有时会将其打印到屏幕上。

The error I have

编辑:

class BinarySearchTree {
    private:
        // Inner class Node, node contains a comprable value and pointers to other Node
        class Node {
            private:
                int value;
                Node * left = NULL;
                Node * right = NULL;
                Node * parent = NULL;

            public:
                // Getter, setter methods for Node
        };

        Node * root; // This is the top node of the tree

public:
    BinarySearchTree (int value) {
        root = new Node(value);
    }
};

1 个答案:

答案 0 :(得分:1)

@dabhaid说。这肯定是你的提示打印在同一行,因为你的输出不是以\n结尾。这是我的zsh,修改后的verbiage:

crap > printf "hey\n"
hey
crap > printf "hey"  
hey%
crap >