Syntax Check while rewriting

Hi,
   I am parsing an AST and rewriting some code. Before rewriting some code,
I want to ensure that the resulting code will compile fine. I am trying to
output variables to a stream (ostream). e.g.

// code to be rewrited
cout<< std::string() <<endl; ( this will compile fine)

// code to be rewrited
cout << new FILE() <<endl; ( this won't compile as no "<<" operator
exists for FILE. Shouldn't rewrite this.)

    How can I find out whether the code of the above type (cout <<
any_type;) will compile fine? I mean, how can I check whether there exists a
"<<" operator for the given type? (I know every compiler does that when
checking the syntax. I just need to know how it does that so that I can
replicate that functionality)

Regards,
Adil