zoukankan      html  css  js  c++  java
  • C++

    思路:

    创建.h的头文件和.cpp的源文件(不是主函数所在cpp)
    头文件中写函数声明
    源文件中写函数定义

    注意:

    这三个代码再codeblocks上不能用,编译器G++的问题?

    devc++ 难道也是??

    先越过这个,等下次换了Qt再来验证,

    反正,

    vs和Linux是可以的。


    主函数:

    #include<iostream>
    #include "swapp.h"
    using namespace std;
    
    int main()
    {
        int x=1,y=2;
        swapp(x,y);
        return 0;
    }

    swapp.h:

    #include<iostream>
    using namespace std;
    
    void swapp(int x,int y); // 函数声明

    swapp.cpp:

    #include "swapp.h" //把cpp和h关联起来
    
    void swapp(int x,int y)
    {
        int t=x;
        x=y;
        y=t;
        //cout包含在另一个头文件中
        //所以需要加iostrem头文件
        cout<<"x = "<<x<<endl;
        cout<<"y = "<<y<<endl;
    }
  • 相关阅读:
    17.10.13
    17.10.12
    17.10.11
    17.10.10
    17.10.05
    17.10.04
    17.10.03
    17.10.02
    17.10.01
    17.9.29
  • 原文地址:https://www.cnblogs.com/OFSHK/p/13062206.html
Copyright © 2011-2022 走看看