passing an ofstream as a void* to a callback function
I want to pass an ofstream as a void pointer but, I do not know how to recast it as a ofstream.
this is what I tried:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
static int cb_xml_ouput(void * ofs, int argc, char **argv, char **col_name)
{
std::ofstream *ofs2 = static_cast<std::ofstream *>(ofs) ;
*ofs2 << "<rec>" ;
for( int i = 0; i < argc; i++ )
{
*ofs2 << '<' << col_name[i] << '>' ;
*ofs2 << (argv[i] ? argv[i] : "NULL") ;
*ofs2 << "</" << col_name[i] << '>' ;
}
return 0 ;
}
|
This function does not compile--how do i do it.
edit: It does compile if you remember to declare <fstream> ; and it works as designed so please ignore this post.
Last edited on
Topic archived. No new replies allowed.