I want a method to limit number of characters than user can type before pressing enter. the reason is i design a form with stars "*" and "=",the problem is when user type let say 25 character as name in front of "Name: " but this field has 15 character space till reach the form border like this..
1 2 3 4 5 6 7
************************
* Name: my name is not fit
* *
* Nationality: Korean *
* *
* IC Number: A12314234234
************************
Not with iostream. iostream will keep sucking characters non-stop (what goes on behind the scenes is a little more complicated, of course). There is no way to change this behavior without using third party libraries.
Although I'm curious as to how you built that rectangle and then went back up to write the "Name:" string. That should be impossible, as well.
Although I'm curious as to how you built that rectangle and then went back up to write the "Name:" string. That should be impossible, as well.
Exactly what I was thinking. The only thing I can think of that is close enough to what you want is to print that information at the very end of all user input and store the largest amount of characters that the user gave as input, which could be used to determine how many asterisks you need.
thou shall need to go a bit lower in streams to do that. I'm pretty sure you can do it with std, it's much eazier with a third party lib tho (IMO, use OS console functions)
What you will need is unechoed input and you just write what you want to be seen yourself.
what you want is to print that information at the very end of all user input and store the largest amount of characters that the user gave as input, which could be used to determine how many asterisks you need.
you could put the *, = thing into a buffer than insert the information in later but that would be harder than just going line-by-line
good idea for the printing out the info but the main problem is when the user input data??