限制用户输入的字符数 [英] Limiting the number of characters of user input
问题描述
我试图限制用户可以输入的字符数。
这不像用户输入 abcde 时,我将输入长度限制为3,< br>
,并且只有 abc 被考虑在内。
I'm trying to limit # of characters a user can input.
It's not like when user inputs abcde, and I limit the input length to be 3,
and only abc is taken into account.
用户输入超过一定数量的字符?
例如,如果用户键入 12345 ,如果我将其限制为3个字符,则只有 123 获取输入。
Is there a way to physically limit user from inputting more than certain amount of characters?
For example, if user trys to type 12345, and if I limit it to 3 characters, only 123 gets typed.
我试过下面的代码:
cin.width );
cin >> n;
cin.width(5);
cin >> n;
但我意识到并不是物理上限制用户输入,而且只限制buffersize的输入。
But I've realized it doesn't physically limit the user input, but only limits the buffersize of input.
有办法做这样的事吗?
Is there a way to do something like this?
+)我正在使用控制台应用程序
+) I'm working on Console Application
推荐答案
不能在标准控制台窗口中,但如果你使用c + +使自己的窗口与您自己的输入框,那么你有一些更多的灵活性。
You can't do it in a standard console window but if you use c++ to make your own window with your own input box then you have some more flexibility.
这篇关于限制用户输入的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!