Answer the question
In order to leave comments, you need to log in
C++: how to make string variable read 1 character at a time?
The situation is this. Available: Cbuilder(1pc) Edith (1pc) User (~1pc). From Edith, the text goes to a variable of type string. Is it possible to read text from a variable by 1 character (for example, the user entered the expression x + 2 = 4, the program looks - yeah, here is X, it goes further, it looks here plus, it goes further here 2, rewrites the deuce into a variable, etc.
Answer the question
In order to leave comments, you need to log in
The user may want to correct the text. Therefore, calculations are best done by pressing Enter or a button on the form. Read the entire line and iterate over 1 character in a loop:
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_RETURN)
{
string input = Edit1->Text;
for (size_t i = 0; i < input.length(); ++i)
{
//тут делайте с input[i] что хотели
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question