func.h
void in(){}
func.cpp
void in(){
printf("HelloWorld");
}
main.cpp
#include "iostream"
#include "func.h"
int main(){
in();
}
error C3861: 'printf': identifier not found
Help me to solve this problem, thanks
func.h
void in(){}
func.cpp
void in(){
printf("HelloWorld");
}
main.cpp
#include "iostream"
#include "func.h"
int main(){
in();
}
error C3861: 'printf': identifier not found
Help me to solve this problem, thanks
Your source file func.cpp
should #include <cstdio>
or perhaps #include <stdio.h>
to declare printf()
before you use it. With <cstdio>
, you get to use namespace std
, so you might write using namespace::std;
after the #include
line, or you might use std::
as a prefix to the function name.
You also need #include "func.h"
in func.cpp
.
func.cpp
— Option 1#include <cstdio>
#include "func.h"
void in()
{
std::printf("HelloWorld");
}
func.cpp
— Option 2#include <cstdio>
#include "func.h"
using namespace std;
void in()
{
printf("HelloWorld");
}
func.cpp
— Option 3#include <stdio.h>
#include "func.h"
void in()
{
printf("HelloWorld");
}
Option 1 is probably the preferred one.
Also, the header should declare the function, not define it, unless you really want an empty function body for the function — in which case you don't need the source file func.cpp
at all.
void in();
Usually, a header should be protected against multiple inclusion. This time, it won't hurt, but it is a good idea to learn good habits:
#ifndef FUNC_H_INCLUDED
#define FUNC_H_INCLUDED
void in();
#endif /* FUNC_H_INCLUDED */