我可以在Visual Studio 2012中编译和调试(运行)单个C ++文件吗? (如何避免创建太多的项目) [英] Can I compile and debug (run) a single C++ file in Visual Studio 2012? (How to avoid creating too many projects)

查看:202
本文介绍了我可以在Visual Studio 2012中编译和调试(运行)单个C ++文件吗? (如何避免创建太多的项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习C ++的一本书,并使用Visual Studio 2012.为了跟随书的练习,我需要使用main()函数内部的多个.cpp文件。 有没有办法我可以编译/调试我的程序,而不是每次都创建一个新的项目

I'm learning C++ out of a book and using Visual Studio 2012. In order to follow the book's exercises, I need to make multiple .cpp files with the main() function inside them. Is there any way I can compile/debug my programs without making a new project every single time?

例如,如果我写一个简单的你好,世界!文件,然后决定做其他的东西真的很简单,我可以避免为每个简单的程序做一个新的项目?有什么方法使用Visual Studio 2012作为一个编译器?我会喜欢它,如果我可以只有一个项目中的一切,我可以编译任何个人文件,我想看到它运行。

For example, if I write a simple "Hello, World!" file and then decide to make something else that is really simple, can I avoid making a new project for each simple program? Is there any way to use Visual Studio 2012 just as a compiler? I would love it if I could just have everything inside a single project where I could compile whichever individual file I wanted and see it run.

感谢您的帮助。 p>

Thanks for your help.

推荐答案

您可以将所有cpp文件添加到具有不同文件名的同一项目,然后您可以右键单击每个文件,不想得到build。

You can add all your cpp files to the same project with different file names then you can right click each file and exclude the files you don't want to get build.

每个应用程序都有一个项目。

It is much better to have a project per application though.

或者,你可以有一个主文件调用你的其他文件中的其他功能,你实现你的练习,那么你不必处理任何东西,只是实现新练习在一个新的文件,并从主调用它。

Alternatively you can have a single main file that calls your other functions in other files where you implement your exercises then you don't have to deal with anything, just implement new exercises in a new file and call it from main.

这篇关于我可以在Visual Studio 2012中编译和调试(运行)单个C ++文件吗? (如何避免创建太多的项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆