operator overloading - Weird characters appear in ostream in C++ -


i have program should emulate simple filesystem, want print structure of directories, have overloaded << operator, , called function goes through structure in rectursion. works, there weird hex values before of lines in output. there wrong way manipulate iwth ostream ? (i did not include class definition, shouldnt matter)

thanks all, answers!

std::ostream& printtree(std::ostream& os, const cfilesystem::tdir* x, int nmbtabs) {     int k;     const cfilesystem::tdir * nxt = x;     //cout << pocettabu<<endl;     while(nxt){         os<<"--";         for(k=0;k<nmbtabs;k++){             os << '\t' ;         }         os<<"--";         os << nxt->m_name << endl;         if(nxt->m_sub){             os << printtree(os,nxt->m_sub,nmbtabs+1);         }         nxt=nxt->m_next;     }     return os; } std::ostream& operator <<(std::ostream& os, const cfilesystem& x) {     os << "/" << endl;     os << printtree(os, x.m_root,1);     return ( os ); } 

os << printtree(os, x.m_root,1); 

what this? printtree returns std::ostream &, , you're trying output (an ostream)?

that should this:

printtree(os, x.m_root,1); 

that means, operator<< should implemented as:

std::ostream& operator<<( std::ostream & os, const cfilesystem & x) {     os << "/" << std::endl;     return printtree(os, x.m_root,1); } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -