VC6怎么调用另一个文件函数

来源:百度知道 编辑:UC知道 时间:2024/06/20 15:55:32
下面VC6里面拆分为两个文件出错在哪里:
文件main.c
#include <iostream>
using namespace std;
extern void ShowLengthOfData();
int main(void)
{
ShowLengthOfData();
return 1;
}

文件WzcFunction.cpp
void ShowLengthOfData()
{
cout<<"the length \"char\" of is "<< sizeof(char)<<endl;
};

出错信息
G:\New\C++\console\WzcFunction.cpp(4) : error C2065: 'cout' : undeclared identifier
G:\New\C++\console\WzcFunction.cpp(4) : error C2297: '<<' : illegal, right operand has type 'char [26]'
G:\New\C++\console\WzcFunction.cpp(4) : error C2065: 'endl' : undeclared identifier
执行 cl.exe 时出错.
1:文件main.c---->我写错了,本就是cpp的。
“形成 .obj 再由调用程序链接。”这个怎么调用的,没用过这类的目标文件。
2:如果改为iostream.h,vc调用的是c编译器,不是c++编译器吧。

#include <iostream>
using namespace std;
这两行放在WzcFunction.cpp文件中,main.c不需要这两行。

iostream不需要改为iostream.h

文件WzcFunction.cpp 里要加 C++ 头文件,
或编译 CL -c WzcFunction.cpp, 形成 .obj 再由调用程序链接。

文件main.c -- 程序扩展名要用 .cpp

#include <iostream>
using namespace std;
改成
#include <iostream.h>