Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I indent cout output?

Tags:

c++

out

I'm trying to print binary tree

void print_tree(Node * root,int level )
 {
    if (root!=NULL)  
    {  
        cout<< root->value << endl;
    }
    //...
}

How can I indent output in order to indent each value with level '-' chars.

like image 523
Fantomas Avatar asked Oct 11 '09 10:10

Fantomas


1 Answers

You can construct a string to contain a number of repitions of a character:

std::cout << std::string(level, '-') << root->value << std::endl;
like image 69
Daniel Earwicker Avatar answered Sep 16 '22 18:09

Daniel Earwicker