Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sprintf not declared in scope?

Tags:

c++

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);
}
like image 685
soniccool Avatar asked Nov 26 '12 03:11

soniccool


1 Answers

You need to include stdio.h.

#include<stdio.h>

The stdio.h declares the function sprintf, Without the header the compiler has no way of understand what sprintf means and hence it gives you the error.

In C++ Note that,

Including cstdio imports the symbol names in std namespace and possibly in Global namespace.
Including stdio.h imports the symbol names in Global namespace and possibly in std namespace.

The same applies for all c-styled headers.

like image 89
Alok Save Avatar answered Sep 17 '22 15:09

Alok Save