C++返回主界面

发布于 10-21 14:05 字数 376 浏览 6 评论 0原文

我希望能够从另一个文件返回 main.cpp 文件。例如。

// Main.cpp
#include "Globals.h"

int main()
{
    otherFile();
}

// Globals.h

#include <iostream>
#include <stdlib.h>

bool otherFile();

//otherFile.cpp
#include "Globals.h"

bool otherFile() 
{
    // do stuff
    // Here I want to be able to go back to the main.cpp file.
}

抱歉,如果我的问题没有意义

I want to be able to get back to the main.cpp file from another. For example.

// Main.cpp
#include "Globals.h"

int main()
{
    otherFile();
}

// Globals.h

#include <iostream>
#include <stdlib.h>

bool otherFile();

//otherFile.cpp
#include "Globals.h"

bool otherFile() 
{
    // do stuff
    // Here I want to be able to go back to the main.cpp file.
}

Sorry if my question makes no sense

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深陷2024-10-28 14:05:34

return 将把控制权返回给调用者,在本例中为 main.cpp 中的 main()

return will return control to the caller, which in this case would be main() in main.cpp.

疧_╮線2024-10-28 14:05:34

如果您在main.cpp中创建一个函数并将声明添加到Globals.h中,那么您可以从otherFile.cpp中调用该函数。

如果“do stuff”后面不需要任何语句,那么你的程序逻辑会自动返回到main(),因为函数调用结束,所以只需在otherFile()后面添加指令即可;在 main 中调用,它们将在该函数之后执行。

您将 otherFile() 标记为返回 bool,因此将函数的末尾 return true;return false;

if you create a function in main.cpp and add declaration to Globals.h, then you can call this function from otherFile.cpp.

If you don't need any statements after "do stuff", then your program logic automatically will return to the main(), because end of function call, so just add instructions after otherFile(); call in main, and they will be executed after this function.

You decalred otherFile() as returning bool, so put and end of your function return true; or return false;

深空失忆2024-10-28 14:05:34

当您完成otherFile()时,您将自动返回main,并且在main()中您将获得return >其他文件()。

You will go back to main automatically when you finish the otherFile(), and in main() you will get the return of the OtherFile().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文