cout to Memo1

This my first post to this forum.
Many years ago I was given a copy of Delphi 4 and C++ Builder 3 by Borland!
I am 91 years of age and I try to program, as a hobby, because as an ex science teacher (Physics) and 'oldie' I need to keep the mental department ticking over.
I have written a Delphi 4 Windows and a Python 'push button' scientific calculator. I am quite pleased with the results. Python does it all for you!
At present I am trying to do the same in C++ Builder. There is an enormous amount of info on the Web but everything I seek seems to be a console application and the output is through 'cout' with endl.
My problem: I am trying to parse an input string into tokens. I have tried to input through an EditBox and out through a Memo but I am getting nowhere.
Any suggestion how or where to look would be greatly appreciated.
Hi Don!

I'm not sure what you mean when you say you are outputting something to a 'memo'. I suspect there may be others that don't know what you are talking about there. Something unique to Delphi or Python perhaps? I don't know those languages.

In terms of parsing strings into tokens, most C++ coders get string parsing code from somewhere; I think there's a big library out there somewhere but I forget the name. I'm sure somebody can jump in to help there.

I do something rather unique to myself, in that I have my own string class that I wrote years ago and have always used in lieu of the string library that is part of the C++ Standard Libraries. As part of that string class I wrote there is a Parse member that parses strings into tokens. I'll give it to you if you want it, but you would likely be better off with the Standard String Class and (it just occurred to me - the Boost Library!) and the various functions in it that parse strings.

Fred
Hi Don -- welcome to the forums,

I don't know what a 'memo' is either, however you may want to look into the Boost Library's string functions like freddie1 suggested. See the use of Boost's split() in this link:

http://www.boost.org/doc/libs/1_52_0/doc/html/string_algo/usage.html#id3331724

Last edited on
A memo is just a edit control, specific to Borland.
I am new to this forum and not sure that my first reply which I submitted was accepted. Just in case then, many thanks to the folk who very kindly swiftly replied to my first post. Thank you DonMac.
If you have C or C++ code that works through an input string representing the type of input a calculator receives such as ...

5 + (6 * 3 -1) + 18 * (4 + 2 * (9-7))

...you could likely use that code on a string retrieved from an edit control (what you are calling a memmo, apparently) in a GUI (Graphical User Interface) application. I did one of these years ago when I was learning C++, but like you said, it was for a console mode environment. But what it did was run through the input string one character at a time counting parentheses and so forth, and running various procedures depending on the characters encountered, such as numbers, '+', '-', '*', '/', etc. I recall it needed to be recursive too - a characteristic that always spices things up a bit.

If you are planning to use Win32 Api coding conventions, you could use GetWindowText() to remove the text string from an edit control. Years ago I used Borland compilers, and contrary to just about everything I read about them nowadays, I really liked them. However, I never got into their 'Object Windows Library' or any of its successors, which were competing with Microsoft's MFC (Microsoft Foundation Classes). These are OOP implementations of the Windows Api.
you could likely use that code on a string retrieved from an edit control (what you are calling a memmo, apparently) in a GUI (Graphical User Interface) application. I did one of these years ago when I was learning C++, but like you said, it was for a console mode environment. But what it did was run through the input string one character at a time counting parentheses and so forth, and running various procedures depending on the characters encountered, such as numbers, '+', '-', '*', '/', etc. I recall it needed to be recursive too - a characteristic that always spices things up a bit.
Good point, I wanted to note that earlier too -- and then once the string is parsed and the content processed, you could output the results to a control/label of your window.

I am currently writing a parser for data that's stored in XML files, and I parse the data much like described above: I use std::string variables, go through the file content one character at a time and look for the character sequences that indicate the opening and closing of XML elements ( '<' , '>' , '</' etc) in order to determine and extract the elements' names. After determining the type of element in each case, the element's content is parsed with a specific function written to handle content for that type of element. And since the number of data entries can vary from one file to the other, the whole should have to be recursive -- much like the input string in a calculator's text box could be of any size and would require a recursive parsing function in order to handle strings of any size and operator sequence.
Last edited on
Thank you freddie 1 and Ogoyant for your very quick responses.
The 'memo' to which I referred should, I believe, have been called a 'MemoBox' and was simply a means of displaying the tokens one above the other, mainly to show the success of the tokenising. I think I could have equally well have used a 'ListBox'
Thanks again DonMac.
Topic archived. No new replies allowed.