ACCU Home page ACCU Conference Page
Search Contact us ACCU at Flickr ACCU at GitHib ACCU at Facebook ACCU at Linked-in ACCU at Twitter Skip Navigation

pinMembers' Letters

Overload Journal #2 - Jun 1993 + Letters to the Editor   Author: Mike Toms

Mike,

I know it helps to get feedback, so here is some regarding the first issue of Overload. I think the content is first rate. As an experienced C programmer, but C++ novice, I found all the articles interesting, useful and well written. I would be happy with more of the same. On the production side, I would like to see more consistent use of fonts. Also, I personally don't like the use of 'script' type fonts in magazines (other than, say, as signatures). Finally, I would prefer to have all the book reviews together in one place. Not, I hasten to add, just because they are in CVu like that. I do genuinely find it preferable.

In summary, an excellent first issue, but a few changes to cater for my own personal prejudices! Well done.
Regards - Ian Cargill

Thanks Ian. Many others who have seen Overload took a dislike to the numerous fonts. I hope you like the new look. Subject matter has now been grouped as much as possible, I hope you like it. Mike Toms

Mike,

Thank you very much indeed for your very interesting first issue of Overload. You asked for letters! The following question on C++ Streams immediately springs to mind, as an idea for inclusion into a future issue. Do you know if there is a "Streams" substitute for getch() and bioskey()?

If you want to read a character without echo, or to get all entered keys in full character code and scancode form as in a line editor, it would be nice to just use the iostream library, instead of having to pull in the CONIO or BIOS library modules just for these functions.

The very best of luck to Overload.
Yours Sincerely - Peter Wippell

To the best of my knowledge there is no such stream function. It is possible to produce one by making a custom streambuf to access the keyboard buffer directly. To accomplish this there are a number of problems to overcome, but I'll look into it for a future article. In the meantime, don't be too upset to bring getch() or bioskey() into your programs. Bioskey is a very small function and will only increase the program size by approximately 70 bytes.

Mike,

Congratulations to you and your colleagues on the first edition of Overload. If it continues the way it has started out it will be one of the best value for money magazines around. I found it very interesting and useful, and the larger format makes it easier reading than CVu, especially the code. In case Francis is reading (and he almost certainly is), I still love CVu. I feel sorry for CUG(UK) members who have not joined the Turbo C++ SIG, because the majority of articles are not Borland specific, but are good, solid standard C++. Since becoming a member of CUG(UK), I have always tried to program in standard C or C++ as this is the line pushed there; quite correctly I believe. Portability is important and careful thought must be given to using special features.

The article on streams looks like being very helpful. Despite studying several books there is still much I don't understand. For example, I wanted a program which would run a loop reading in a string and a value, and print them out. In simplified form it looks like this:

#include <iostream.h> main()
{
charbuf[100];
double value;
do
{
cin.get(buf,100); // cin >> doesn't work with spaces
cin >> value;
cout << buf << " " << value << endl << endl;
} while (value != 0);
return 0;
}

The program goes into uncontrolled looping the second time round the loop. Perhaps you or another reader can help.

By way of a contribution, I have a rough and ready boolean class which I have used. I will try and polish it up and send it in.

Wishing you continued good fortune with the magazine.
Yours Sincerely - Jim Bartholomew

I hope we can continue to please you Jim. I agree with your views on writing standard code, however, in order to exploit products such as OWL and Turbo Vision, non-standard code must be used.

The problem with your program is that the cin >> double whilst extracting the characters of the double number it leaves the carriage-return in the stream. If you add the line char scrap at the start and perform a cin.get(scrap) after the extract your double will find that the CR is removed. This should cure your looping. P.S. You should also test the return status of the stream after input (see this issues streams article). Mike

Mike,

RE: Overload Issue 1 - Article on Streams.

Streams seem to be a really useful feature of C++ and its a great pity that they are grossly underused. Your series of articles will do a great job in helping to put that right. If I may, I would like to add a little to the discussion on strstream in the first article.

First, under Problems with 'ostream', to get rid of a frozen string when you have finished with it, all you have to do is delete it. So the final lines of the example under automatic memory allocation might be amended to read:-

char *frozen = buffer.str(); // freeze the string
cout << frozen; // output to the console
delete [] frozen; // remove it from the heap

Used this way, ostream becomes an extremely useful replacement for both scanf() and malloc() with much improved formatting facilities.

Second, from under From-Memory reading, in the example, the removal of whitespace and the use of the 'get' member function is not necessary. The same output is obtained by erasing those lines and adding " >> s1 >> s2; " to the main stringstream output line. The example below shows how you can read a string of several words separated by whitespace, if it is the final string in the buffer or there is a convenient terminator. Otherwise you would have to read word by word as in the article.

// From-Memory reading amended to read
// the final string
#include <strstream.h>

int main()
{
char memory_info[] = "100 200 22.995 hello fred";
int i1, i2;
float f1;
char s[20];
istrstream stringstream(memory_info,
sizeof(memory_info));
stringstream >> i1 >> i2 >> f1;
// stringstream >> ws; // to remove whitespace
// if required
stringstream.get(s, 20, '\0');
cout << i1 << endl
<< i2 << endl
<< f1 << endl
<< s << endl;
cin.peek(); // nearest I can get to getch() but you have
// to hit return return 0;
}

Good Luck to Overload
- Peter Wippel (again)

The delete [] freeze certainly works. I am paranoid about identifying the matching pairs of new/delete operators. How would I cope with missing new statements? It is not too difficult to use:-

buffer.rdbuf()->freeze(0);

The initial streams articles are only intended to give a brief overview. More detail to follow! - Mike.

Overload Journal #2 - Jun 1993 + Letters to the Editor