简体   繁体   English

代码块始终在项目中运行 main.cpp

[英]Code blocks always runs main.cpp in a project

I have code blocks 17and i created a new project.我有代码块 17 并且我创建了一个新项目。

  1. Clicked create new project单击创建新项目

2.Console application 2.控制台应用

3.C++ 3.C++

4.Gave it a name and stored it in an empty folder 4.给它一个名字并将它存储在一个空文件夹中

5.Created new file inside the project and wrote some code. 5.在项目中创建新文件并编写一些代码。

When i build, it builds without errors.当我构建时,它构建没有错误。 When i run it, It always runs main.cpp by default.当我运行它时,它总是默认运行 main.cpp。 How do i execute other files without having to run main.cpp everytime.我如何执行其他文件而不必每次都运行 main.cpp。

It doesn't run main.cpp - it runs the main() function, which might be in any named .cpp file - a file with the name main.cpp is not special as far as Code::Blocks, or C++ in general, is concerned.它不运行 main.cpp——它运行 main() 函数,它可能在任何命名的 .cpp 文件中——一个名为 main.cpp 的文件对于 Code::Blocks 或 C++ 来说并不特殊, 被关注到。 But a Code::Blocks project can only have one main() function.但是一个 Code::Blocks 项目只能有一个 main() 函数。

从它的外观来看,您可以从项目中删除 main.cpp 文件,或者只是将int main()函数添加到您想要的文件中并删除 main.cpp 中的一个

您需要在运行之前构建一个文件,因此不必只提供 run 给 build&run 选项。

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

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