I'm trying to define this inline function. It would create a decision tree (a particoular binary tree used in operations research).
This is the code:
inline void printTreeFile(int* i_node,int* j_node,int* q_infr,int* value,int nStart,int level,std::fstream& tree)
{ int spazi=0,len,stop;
for(int actual_level=0;actual_level<level;actual_level++)
{spazi+=9;
if(i_node[actual_level]==0)
len=1;
else
len=(int)log10(i_node[actual_level])+1;
spazi+=len;
if(j_node[actual_level]==0)
len=1;
else
len=(int)log10(j_node[actual_level])+1;
spazi+=len;
if(q_infr[actual_level]==0)
len=1;
else
len=(int)log10(q_infr[actual_level])+1;
spazi+=len;
}
if(value[level]==0)
{
tree<<"-->("<<i_node[level]<<","<<j_node[level]<<","<<q_infr[level]<<"=1)";
tree<<endl;
for(int i=0;i<spazi;i++)
tree<<" ";
tree<<"-->("<<i_node[level]<<","<<j_node[level]<<","<<q_infr[level]<<"=0)";
}
else
tree<<"-->("<<i_node[level]<<","<<j_node[level]<<","<<q_infr[level]<<"=1)";
//cin>>stop;
}
The std::fstream& tree
is defined in main as:
fstream tree;
remove("tree");
tree.open("tree",ios::out|ios::app);
I don't understand why the file tree
is empty until is executed the command tree<<endl;
I need to see how the tree evolve itself without waiting for that command...anyone know a solution to this problem? thanks to all that will answer!