C++ 实时控制台应用程序,同时输入和输出

发布于 2024-07-29 17:51:23 字数 397 浏览 1 评论 0原文

我正在为某些东西编写一个快速服务器应用程序,所以不想编写完整的 GUI。 然而问题是服务器的主要部分,但是控制台窗口一次只允许输入或输出。

我玩过的许多游戏都有一个控制台(通常需要以某种方式激活),他们通过分离输入和输出来解决这个问题,这样底线专门用于输入输入命令,而其余部分用于输出就像普通的控制台窗口一样。

是否可以以最少的工作量(即无需从头开始编写自己的控制台窗口)并以跨平台的方式完成类似的事情? 理想情况下,当服务器在没有安装所有 GUI 内容的系统上运行时,我仍然喜欢以某种方式使用正常的命令提示符,尽管我猜想一个可以与服务器连接的简单 GUI 客户端也可以。

我所说的跨平台是指需要 Windows 和 Linux 支持。 虽然如果我使用客户端 GUI 路由 ID,那么除此之外还需要 Mac。

I'm writing a quick server app for something so don't really want to write a full GUI. However the problem is that the main part of the server, however the console window will only allow input or output at a time.

Many games ive played that have a console in them (usually needs activating in some way or another) they solved this problem by separating the input and output, such that the bottom line is dedicated to entering input commands, while the rest is used for output like a normal console window.

Is it possible to do something like that with a minimal amount of work (ie without having to write my own console window from scratch), and in a cross platform way? Ideally id like to still use the normal command prompt somehow for the case where the server is running on a system without all the GUI stuff installed, although I guess a simple GUI client that could connect with the server would be fine as well.

By cross platform I mean Windows and Linux support is required. Although if I went the client GUI route id also require Mac on top of that.

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

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

发布评论

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

评论(3

亢潮 2024-08-05 17:51:23

听起来你应该看看 curses

ncurses

pdcurses

Sounds like you should have a look at curses

ncurses

pdcurses

安人多梦 2024-08-05 17:51:23

现在的 GUI 构建器非常简单。 您可能会发现,单击 GUI 比按您想要的方式解决此问题更容易。

我对跨平台部分有点不确定。 您能否缩小范围并具体说明您想要哪些平台?

如果您正在考虑 Linux(它本身是跨平台的,至少在某种程度上),那么我会看看 ncurses。

GUI builders these days are very easy. You might find that clicking together a gui is easier than solving this the way you want.

I'm a bit uncertain about the cross-platform part. Could you narrow it down a bit and specify which platforms you have in mind?

If you are considering Linux (which in itself is cross-platform, at least to some extent), then I'd take a look at ncurses.

欲拥i 2024-08-05 17:51:23

您可能想研究一下线程。 主函数将处理输入,而分离线程可以查看输出。 我使用线程的概念来实现实时搜索,当您按下某个键时,您会立即获得结果,同时通过在分离的线程中处理输入来保持输入的活动状态。 这样您就可以继续输入,同时仍能更新结果。

You might wanna look into threads. Main function will process the input while the detached thread can look into the output. I used the concept of threads to achieve Real-Time search where when you press a key you get immediate results while still keeping the input alive by keeping the processing of the input in a detached thread. This way you can keep typing while still getting the result updated.

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