如何在执行main之前显示字符串 [英] how to display a string before main get executed

查看:67
本文介绍了如何在执行main之前显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我知道如何完成此操作.谢谢

Please let me know how to get this done. thanks

推荐答案

正如其他人指出的那样,这没有太大意义:为什么不只打印文本在您的主要方法开始时?

无论如何,我想有一种方法可以在main之前打印一些东西:拥有一个全局静态变量,可以通过调用一个函数来初始化它:

As others pointed out, this doesn''t make too much sense: why don''t you just print your text at the beginning of your main method ?

Anyway, I guess there''s a way to print something before the main: have a global static variable which is initialized by calling a function:

static int myVar = PrintString();

int PrintString() 
{
   cout << "My string";
   return 0;
}



但是我看不到您为什么要在这里做类似的事情...此外,如果您需要多次,则无法定义初始化顺序(如果静态变量在单独的位置



But I don''t see any reason why you would like to do something like that here... Furthermore, if you need this multiple times, there''s no way to define the initialization order (if the static variables are in separate compilation units).


在应用程序启动之前,您无法在应用程序内执行任何操作来显示字符串,但是,您可以使用脚本执行类似的操作……您可以创建一个应用程序启动脚本,该脚本将在启动应用程序之前执行所需的任何操作.
There''s nothing you can do within the application to display a string before an application starts, however, you can use scripts to do something like that... you can create an application launch script that''ll do whatever you need before starting the application.


您可以通过
You can specify an alternate starting address via the Linker[^], but it is not really that different from starting at the normal point. Perhaps if you explained in more detail exactly what problem you are trying to solve someone may have a useful suggeston.


这篇关于如何在执行main之前显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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