So I have the following code snippet:
cout << "Enter input: " <<endl;
cin >> input;
I want to just check the first character that the user enters, but the user is supposed to enter multiple characters. If I use a try block to check the user input, the block repeats for each character entered after the first one. How I can I solve this problem?
Since you tagged it C++, I'll assume input
is a std::string
. Try input[0]
. This should return the first character.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.