I have a small snippet of code here from something I designed but I keep getting the error :
sprintf not declared in scope
Do I include something in the #includes or how can I get this working? I was working on it on VS at my mom’s but came home and I can’t get it on code blocks
if (tmp2 <= B_dest[hr - 6])
{
sprintf(name, "B%d", tmp3);
}else{
sprintf(name, "A%d", tmp3);
}
You need to include
stdio.h.The
stdio.hdeclares the functionsprintf, Without the header the compiler has no way of understand whatsprintfmeans and hence it gives you the error.In C++ Note that,
Including
cstdioimports the symbol names instdnamespace and possibly in Global namespace.Including
stdio.himports the symbol names in Global namespace and possibly instdnamespace.The same applies for all c-styled headers.