I
I
Ilya Korablev2015-12-01 19:48:09
C++ / C#
Ilya Korablev, 2015-12-01 19:48:09

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

3 answer(s)
A
Anatoly Medvedev, 2015-12-01
@balamyt92

Just started learning this PL from the game "Bulls and Cows"

Bad idea. Read books on the language to begin with, or at least sites on the topic.
About the question. It all depends on the input method. Sample algorithm:
I don’t give the code, but I suggest reading about cin and conditional operators.

V
Vladimir Martyanov, 2015-12-01
@vilgeforce

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")){...}

O
Oleg Tsilyurik, 2015-12-01
@Olej

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 question

Ask a Question

731 491 924 answers to any question