C ++ implements the C language printf function
// Simple implementation of the printf function in C Language
# Include
# Include
# Include
Using namespace std;
Void print (const char * str) // when only strings are processed
{
Cout <str <endl;
}
Template
Void print (const char * str, T t, Args... args)
{
If (* str) = '\ 0' | str = NULL) // exit the recursive Condition
{
Return;
}
If (* str = '% ')
{
Switch (* (++ str) // here, only a few are implemented to represent
{
Case 'D ':
If (strcmp (typeid (t). name (), "I "))
{
Cout <"parameter type does not match! "<Endl;
Return;
};
Break;
Case 'C ':
If (strcmp (typeid (t). name (), "c "))
{
Cout <"parameter type does not match! "<Endl;
Return;
};
Break;
Default:; break;
}
Cout <t;
Print (++ str, args ...);
}
Else if (* str = '')
{
Cout <'';
Print (++ str, t, args ...);
}
Else
{
Cout <* str;
Print (++ str, t, args ...);
}
}
Int main ()
{
Return 0;
}