简体   繁体   English

如何使用Ansi C打开新的控制台窗口?

[英]how to open new console window using Ansi C?

i am beginner in Anci c programming here is the description for my program my program first asks user to press any key then a new console is opened and the user inputs any number he want then the console is closed and the number he typed is printed in the parent console ,i hope this clear and thanks for reply 我是Anci c编程的初学者,这是我的程序的说明,我的程序首先要求用户按任意键,然后打开新的控制台,然后用户输入所需的任何数字,然后关闭控制台,并打印出他键入的数字父控制台,我希望这很清楚,感谢您的答复

so i want the function that opens a new console i am using Code::Blocks gcc compiler under win 7 所以我想打开在Win 7下使用Code :: Blocks gcc编译器的新控制台的功能

"ANSI C" doesn't know there is such a thing as "consoles" or "windows". “ ANSI C”不知道存在诸如“控制台”或“ windows”之类的东西。 This is almost certainly going to depend on the operating system and/or windowing environment being used, as well as any third-party libraries being used to drive these kinds of operations. 几乎可以肯定,这将取决于所使用的操作系统和/或窗口环境,以及用于驱动此类操作的任何第三方库。 Maybe something like ncurses would be helpful here, but there's no way of knowing without more specific information. 也许像ncurses这样的东西在这里会有所帮助,但是没有更具体的信息就无法知道。

ANSI C doesn't have a concept of "windows". ANSI C没有“窗口”的概念。 That's an operating system concept outside the area of the C language. 那是C语言范围之外的操作系统概念。

As people have mentioned, this doesn't make sense for ANSI C. For Windows, you'll need to be more specific about what you want. 就像人们已经提到的那样,这对于ANSI C来说是没有意义的。对于Windows,您需要更加具体地了解所需的内容。

If you're writing a console application (done automatically if you're using main , or if you explicitly pass the /SUBSYSTEM:CONSOLE flag to the linker), you don't need to do anything special. 如果您要编写控制台应用程序(如果使用main或将/SUBSYSTEM:CONSOLE标志显式传递给链接器,则自动完成),则无需执行任何特殊操作。 Running your application from a windowed application will spawn a console window for you. 从带窗口的应用程序中运行应用程序将为您生成一个控制台窗口。 Running it from an existing console window will reuse that one. 从现有的控制台窗口运行它会重复使用该窗口。

If you're writing a windowed application (done automatically if you're using WinMain , or if you explicitly pass the /SUBSYSTEM:WINDOWS flag to the linker), you can use AllocConsole . 如果您正在编写窗口应用程序(如果使用WinMain会自动完成,或者将/SUBSYSTEM:WINDOWS标志显式传递给链接器,则可以自动完成),则可以使用AllocConsole See the Creation of a Console article from MSDN. 请参阅MSDN中有关创建控制台的文章。 (I think you also should be able to do that if you're writing a console application and never want to reuse an existing console, but I'd have to say that doing so would be very user-unfriendly.) (我认为如果您正在编写控制台应用程序并且从不希望重用现有控制台,那么您也应该能够做到这一点,但是我不得不说这样做对用户非常不友好。)

system("cmd");

应该可以

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

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