English 中文(简体)
使用输出流来显示“游戏中”的文本是个好主意吗?
原标题:Is it a good idea to use output stream to display text "in-game"?

Let s say I m making a game where text can be displayed and scrolled/okay d when ENTER is pressed. Is it a good idea to use a output stream class and send my "raw" std::string to it? I m thinking about doing this so it d be easier to either send the messages to the console or to the actual screen using an fancy display style

谢谢

最佳回答

没有什么可以阻止您创建自己的流缓冲区类,然后可以转发到std::cout,或者在稍后的时间点做一些更奇特的事情。

我建议在这里阅读这篇文章http://spec.winprog.org/streams/关于iostream和使用提供给您的内容滚动自己的iostream。阅读本文以了解正在发生的事情。

Boost IO流库使您更容易创建自己的流:

http://www.boost.org/doc/libs/1_43_0/libs/iostreams/doc/index.html

问题回答

如果“原始”字符串由可打印文本组成,则使用运算符<<打印,例如:

// Display prompt to user
std::string output("Please press <ENTER>: ");

std::cout << output << std::flush;

// Wait for user to press <Enter>
std::string input;

std::getline(std::cin, input);




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签