请问:我现在有一个VC程序,要用到以前的一个C程序和一个C++程序的功能如函数,我应该怎么样能调用?不会要把它们改造成一个C++程序吧,请给出较为详细的说明,谢了!

解决方案 »

  1.   

    如果是c的
    在代码前面加
    EXTERN "C"
      

  2.   

    可以将原c。c++程序的函数做成传统dll,然后将其加入工程里,就可以调用它了
      

  3.   

    如果有头文件,直接在需要用这些函数的文件中加入#include "yourfuc.h"即可
      

  4.   

    自定义一个类,你可以这么做,例如下面的例子是做一个类 MyFunc ,其中有个函数 FindChar 功能是用来查找字符串中某个指定字符,并输出。
    1.定义 myfunc.h 
    //myfunc.h 2004-03-30 WGF Wuhan
    class MyFunc
    {
    public:
      void FindChar(string strSource, char chr);
    };2.函数 FindChar 的功能实现
    //myfunc.cpp 2004-03-30 WGF Wuhan
    #include <string>
    #include <iostream>using namespace std;#include "myfunc.h"
    void MyFunc::FindChar(string str, char chr)
    {
      string::size_type pos = 0;
      while((pos = str.find_first_of( chr , pos )) != string::npos)
      {
        cout << "found blank at index: " << pos << " is " << str[pos] << endl;
    ++pos;
      }
    }3.在VC中测试用我们刚写好类,这里我们新建一个 Win32 Console Application,假设名称为 MyTest,加入我们写好的 myfunc.h 和 myfunc.cpp 文件,然后新建一个 mytest.cpp 来作为测试程序。
    //mytest.cpp 2004-03-30 WGF Wuhan
    #include<string>
    #include<iostream>using namespace std;#include "myfunc.h"int main()
    {
    MyFunc myfunc;  //声名一个实例 string str1 = "void main() { cout << \"Hello, World!\" << endl; }";
    char chr = 'o'; myfunc.FindChar(str1, chr); return 0;
    }我想你知道怎么做了吧。