Pure Beginners Question : Must be Impossibe

There's no way I can make a border of characters around the whole screen. After hours of just tampering, I've given up on hope that a cout and cin can go on the same line. It seems like it should be really simple to this since games back then were just like this but is there any simple solution to this problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string border, name, choice;

	cout << "Enter one or more characters to create the menu border design." << endl;
	cin >> border;
	cout << "\n" << endl;
	cout << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << endl;
	cout << border << "                                                                       " << border << endl;
	cout << border << "                 " << " Put your name on the line right now" << "                  " << border << endl;
	cout << border << "                                                                       " << border << endl;
	cout << border << " "; cin >> name;
	cout << border << " "; cout << "Ok, spectacular, " << name << endl;
	cout << border << "\n" << border << endl;
	cout << border << " "; cout << " Find a direction you wanna go:" << endl;
	cout << border << " "; cout << "left" << endl;
	cout << border << " "; cout << "right" << endl;
	cout << border << " " "straight" << endl;
	cout << border << endl; cout << border << " What direction have you chosen to go?" << endl;
	cout << border << "\n" << border << endl;
	cout << border << " "; cin >> choice;
	cout << border << "\n" << border << " " << choice << "." << " is where you go then" << endl;
	cout << border << "\n" << border << endl;
	cout << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << border << endl;



	system("pause");

	return 0;




Man how long can a window get
Last edited on
What you are trying to do is impossible with standard C++. Your program will just output one character after another, and there is no way to go back up a few lines.

If you really want to make it work you can use a library such as ncurses on Linux, or the WinAPI on Windows, but that's a bit more advanced.
make sure to understand what is a stream .
You really think that is the solution to the problem. So was my court << border codes redundant then?
from line 12 to 28 you could have a single cout.
What I am saying is that cin streams data from the console to the user , cout streams data from the user to the console. If you want to do like an interface , note that you will have to use coordinate I think of the function gotoxy and flush the console as well.
It seems like it should be really simple to this since games back then

It wasn't "really simple" back then either.

The thing is that there are no screens nor windows as far C++ is concerned. There is OS (which might be implemented with C++, but that is irrelevant). A regular C++ application can call the API of the OS. The OS in turn has means to do something with the monitor. There are usually a chain of components rather than "OS".

Games "back then" did use the OS, or did by-pass the OS and did the hard work themselves. If the game did not have code for device Y, the game could not use Y. The OS has code for many devices, so games don't need to care what the computer has. One API works more or less the same with all devices. Modern OS do not allow by-pass (it is a security issue).

Different OS have different API and the function calls can be complex. A library like ncurses is an another layer of simplification. It offers API to do the type of operations that you "easily". There are also versions of ncurses for multiple OS, so the application does not need to know the OS.
You could use nCurses- depending on your platform.
You may try with:

#include <iomanip>
then you can set field width
using the setw function
http://www.cplusplus.com/reference/iomanip/setw/

For a cin for instance, I'm pretty sure it can't be done within the code.
Last edited on
I could have a single cout Ericool, but that'd be way too hard to follow. That window was long enough with borders. Anyway so having a cout statement after a cin appear on the same visible line is impossible? Thanks for all the input, I might need to use some of these tips later on. I'll post if my professor had a solution or other way of doing this.
Panda187 wrote:
so having a cout statement after a cin appear on the same visible line is impossible?

You can use cout to output what comes before cin but when it reaches the cin statement it stops and waits for the user input so the right border on that line and everything below will not be outputted yet.

Panda187 wrote:
I could have a single cout Ericool, but that'd be way too hard to follow.

Just because you use a single cout statement doesn't mean you can't put it on multiple lines. This doesn't really have any real advantage though, except it repeat the cout keyword less times.

Panda187 wrote:
That window was long enough with borders.

If you have learned about loops, you could use a loop to output the top and bottom border instead of repeating << loop so many times.
Thank you very much Peter, very helpful tips.
Last edited on
I saw a post the other day that I thought was simply awesome. I haven't looked at it in detail to see how it works but you might take a look.

http://www.cplusplus.com/forum/general/173362/

look for the reply from whitenite1.

Thanks but I went to the link but threes only three posts in it from Zhuge and prajesh. Maybe wrong link?
Topic archived. No new replies allowed.