我从我设计的东西这里有一小段代码,但我一直在获取未在范围内声明的错误sprintf?
我是否在#includes中包含了一些内容,或者我如何才能使其正常工作?我在我妈妈的VS上工作,但回到家里,我不能在代码块上得到它
if (tmp2 <= B_dest[hr - 6])
{
sprintf(name, "B%d", tmp3);
}else{
sprintf(name, "A%d", tmp3);
}
Run Code Online (Sandbox Code Playgroud)
Alo*_*ave 27
你需要包括stdio.h.
#include<stdio.h>
Run Code Online (Sandbox Code Playgroud)
该stdio.h声明的功能sprintf,没有编译器无法理解的方式头sprintf表示,因此它给你的错误.
在C++中请注意,
包括cstdio在名称std空间中导入符号名称,可能还包括在Global名称空间中.
包括stdio.h在Global名称空间中导入符号名称,也可能在std名称空间中导入.
这同样适用于所有c风格的标题.
确保你有 #include <cstdio>
并按照std::sprintf()@Potatoswatter的指示访问sprintf .
或者做旧的c风格:#include <stdio.h>包括sprintf的定义.