get number of input characters befor press enter

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
 ************************


Last edited on
It's not possible with iostream. How are you interacting with the console?
hmm.. yeah I use iostream!! so you mean there is no solution??
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.
Last edited on
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.
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.

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
Last edited on
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.


Bottom line: find another, eazier solution.

PS: Streams are not made for forms.
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.


well! for this i use the gotoX_Y(int x,int y):

1
2
3
4
5
void GotoX_Y(int x,int y){
    COORD coord;
    coord.X = x; coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


so in the main i use it like:

1
2
3
4
5
GotoX_Y(15,11);
cin>>name;
mngobj.SetName(name);
GotoX_Y(20,13);
cin>>ic;mngobj.SetIcNumber(ic);



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??

I was thinking of writing app to be look like to this :
http://www2.apebox.org/wordpress/wp-content/gallery/00-single/osctool3-ncurses-04.png
but could not find any lib for that does any one of you guys have idea about this?
I think libraries with supporting this graphical interfaces are more suitable for my problem
Last edited on
Look at the last few characters in the URL you posted:
ncurses
Topic archived. No new replies allowed.