Answer the question
In order to leave comments, you need to log in
How to validate the entered phrase?
Hello. How to check by phrase in C++? I just started learning this PL from the game "Bulls and Cows".
For example, if message help
, then is calledcout << N;
Answer the question
In order to leave comments, you need to log in
Just started learning this PL from the game "Bulls and Cows"
If your input string falls into the std::string type, it is written like this: if (inStr == "help"){...}. If it is an ordinary char[] string, then this: if (!strcmp(inStr, "help")){...}
It all depends very much on whether your phrase is limited to English text (ASCII characters), or it can be Russian (or Chinese).
In the 1st case, you can do with symbols everything that is written in books ... or what you are now advised here in the answers. ;-)
In the 2nd case, if you store the string in char[] / string, then you should be prepared for the fact that strlen() will give erroneous values, find() and other similar things will work "wrong" ... and, in general, you will not be able to work with the content: search, divide into parts, select substrings. But you can store, compare and display strings in this way (i.e. work as a single entity).
Another option is to store such strings as "wide characters", 4 bytes: wchar_t[] / wstring. But there are some inconveniences...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question