编译你的第一个程序

随着程序变得更大,这种情况并不少见组织的目的将它们分割成多个文件。 带有IDE工作的一大优势是他们让多个文件更容易工作。 你已经知道如何创建和编译单个文件的项目。 现有项目添加新文件是很容易的。

在Visual Studio 2005 Express中,右键单击“源文件”在解决方案资源管理器窗口的左边,选择“添加” - >“新建项目”。 给新的文件名称,它将被添加到您的项目。

在Code :: Blocks的,“文件”菜单中,选择“新文件”。 给新的文件名称,Code :: Blocks的会问你,如果你想将它添加到活动项目。 点击“是”。 请注意,您也将有点击“发布”和“调试”复选框,以确保它被添加到这两个版本。

编译您的项目只是像以前一样。 无法容易得多!

现在,考虑下面的多档节目:

add.cpp:

1
2
3
4
int add(int x, int y)
{
    return x + y;
}
main.cpp:

1
2
3
4
5
6
7
8
#include <iostream>
 
int main()
{
    using namespace std;
    cout << "The sum of 3 and 4 is: " << add(3, 4) << endl;
    return 0;
}

Try compiling this program for yourself. You will note that it doesn’t compile, and it gives the same compiler error as the program in the previous lesson where the functions were declared in the wrong order:

add.cpp(10) : error C3861: 'add': identifier not found
add.cpp(15) : error C2365: 'add' : redefinition; previous definition was 'formerly un


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值