简体   繁体   English

Visual C ++,整理文件夹中的.h和.cpp文件

[英]Visual C++, Organize .h and .cpp Files in Folders

I've never had a C++ project that has required organizing stuff in folders before, because I mostly use C# for everything, but now I have this kind of project. 我以前从来没有一个C ++项目需要组织文件夹中的内容,因为我大多数情况下都使用C#,但是现在我有了这种项目。 What I have done is right click on "Header Files" in the solution explorer, and looked for "Add Folder", but there is no such thing. 我所做的是右键单击解决方案资源管理器中的“头文件”,然后查找“添加文件夹”,但是没有这样的事情。 However, there is something called a "Filter", and it appears to work like a folder, but I don't know if this is how C++ uses folders, or what. 但是,有一个叫做“过滤器”的东西,它看起来像一个文件夹,但是我不知道这是C ++使用文件夹的方式还是什么。 Is this the case, using filters as folders, or is there a way to make folders? 使用过滤器作为文件夹时是这种情况,还是有办法制作文件夹?

Thanks for your help. 谢谢你的帮助。

You can use filters if you like. 您可以根据需要使用过滤器。 These place files into pseudo-folders based on their file extensions. 这些文件根据文件扩展名将文件放入伪文件夹。 By default, you get header files in "Header Files", source files in "Source Files", etc., but these are customizable, as you've found out. 默认情况下,您在“头文件”中获取头文件,在“源文件”中获取源文件等,但是如您所知,它们是可自定义的。

However, if you prefer the Solution Explorer to reflect the file system, then that is an option as well. 但是,如果您希望解决方案资源管理器来反映文件系统,那么这也是一个选择。 Just click the "Show All Files" button at the top of the Solution Explorer to toggle it on. 只需单击解决方案资源管理器顶部的“显示所有文件”按钮即可将其打开。 The filters will no longer be active (although they'll still be saved with your project settings so that you can toggle them back on at any time), and you will see the folders exactly as they are in the file system. 筛选器将不再处于活动状态(尽管它们仍将与您的项目设置一起保存,以便您可以随时将其重新打开),并且您将看到与文件系统中的文件夹完全相同的文件夹。 You can drag-and-drop files between folders, create new folders, and everything, just as you normally would. 您可以像往常一样在文件夹之间拖放文件,创建新文件夹以及所有内容。

(overcompressed JPG image stolen from Ben Williams' blog ) (从Ben Williams的博客中窃取的过压缩JPG图像)

I prefer to keep the filters disabled and see the file system in the Solution Explorer. 我更喜欢禁用过滤器,并在解决方案资源管理器中查看文件系统。 But I'm a control freak—I like files to be exactly where I put them. 但是我是个控制狂-我喜欢文件放置在正确的位置。

The obvious drawback of this, of course, is that you'll see all files in your solution's directory on disk, even those that have not been added to your project/solution. 当然,这样做的明显缺点是,您会在磁盘上看到解决方案目录中的所有文件,甚至包括那些尚未添加到项目/解决方案中的文件。 Those that have not been included will appear grayed out or with a dotted outline, and can be easily included by right-clicking and selecting "Include In Project." 那些未包括在内的项目将显示为灰色或带有虚线轮廓,并且可以通过右键单击并选择“包含在项目中”轻松地将其包括在内。

You can add projects to Visual Studio solution. 您可以将项目添加到Visual Studio解决方案。 Each project would be in separate folder. 每个项目将位于单独的文件夹中。 They also can be stored hierarchically. 它们也可以分层存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM