开发者

C++ Draw program, split in groups of two

I would like to make a draw application. I want to enter user names until eg "end" is entered and then the program to split them in groups of two. Can you suggest any examples? I don't know how to start! If possible, I want to be Cross-platform. If it isn't possible I want lin开发者_运维百科ux.


Assuming I'm understanding your question correctly:

Pseudocode:

while the user is entering user names
    store the user name in a list

for half the number of items in the list
    remove a random item from the list
    add that item to a second list

Here's a tutorial on using the STL container classes. You'll probably want to go with the std::list: http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html


The iostream libraries in C++ are for reading and writing lines of text through a command line interface:

http://en.wikipedia.org/wiki/Command_line_interface

On the plus side of these libraries, they are very standardized and every C++ compiler offers them. They work on Windows, Linux, or any other platform.

On the downside of these libraries, you can only read and write lines of text. You cannot draw circles around your names, or position them freely in the window. The only kind of "drawing" you can achieve with them is ASCII art.

This tutorial shows you basic input and output in C++:

http://www.cplusplus.com/doc/tutorial/basic_io/

If you want more freedom in drawing arbitrary graphics, that's not part of the C++ language specification. You'll need a third-party library, which may or may not be provided on multiple platforms.

Some of these libraries have routines for drawing text strings on the display in arbitrary fonts. Others just provide a display area and expect you to do text drawing yourself or with a library like FreeType:

How do I draw text using OpenGL, SDL and C++?

It's probably best to avoid the complexity of graphics if you're just getting started with C++ as a language. Better to follow along with a few more basic tutorials, and you should be able to adapt the pseudocode Cogwheel gave you to get it. (People on StackOverflow don't like to directly write code for simple problems because that often amounts to doing someone else's homework.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜