如何在一个VC工程中添加多个cpp文件
如题:比如我写两个cpp文件
4_1\tv.cpp//:
#include<iostream.h>
void main()
{
cout<<"testing number 1"<<endl;
test();
}
tv.cpp//:
void test()
{
cout<<"testing number 2"<<endl;
}
编译的时候会有: error C2065: 'test' : undeclared identifier
error C2065: 'cout' : undeclared identifier
D:\VC++工程\OpenGL程序设计4_1\tv.cpp(8) : error C2297: '<<' : illegal, right operand has type 'char [17]'
D:\VC++工程\OpenGL程序设计4_1\tv.cpp(8) : error C2065: 'endl' : undeclared identifier
执行 cl.exe 时出错.
然后我在tv.cpp中添加#include <iostream.h>
并在4_1\tv.cpp中进行函数声明:void test();
即修改之后的程序是:4_1\tv.cpp:
#include<iostream.h>
void test();
void main()
{
cout<<"testing number 1"<<endl;
test();
}
tv.cpp//:
#include<iostream.h>
void test()
{
cout<<"testing number 2"<<endl;
}
则运行正确。
那么必须在tv.cpp中加如#include<iostream.h>吗?我已经在4_1\tv.cpp中加入了include<iostream.h>,还需要在tv.cpp中加入吗?是不是必须的?
还有,必须在4_1\tv.cpp,即含有主函数的cpp文件中声明在其他cpp文件中写的函数吗?如上面的void test();
谢谢。