July 18, 1997

Using strstream for ‘incore’ binary I/O

Question: Can I use strstream functions for incode I/O,i.e. writing to memory just as if it were binaryinput/output to a file? Answer: You can use it to do incode input and output but there is no way to make it behave like a binary store, i.e.:strstream s;s

Constructors and virtual functions

Question: I have been doing some programming in C++ and recently decided I would try some Windows programming with the Microsoft Foundation Classes. This isn’t a question about Windows but about something I saw in the MFC. Applications are derived from a class called CWinApp but the only function I

Clearing character arrays

Question: How do you clear a character array? Answer: You can use the standard C library memset function. Here is an example:void foo (){ char t [20]; cin >> t; cout

Declaring a bit field for a variable

Question: Is there a way to explicitly declare the number of bits to allocate to a specific variable? For example, can I declare an integer that would be stored in nine bits? Answer: Here is the syntax to define bitfields in C/C++:struct bitField{ int a:1; // a has one bit

Helpful C/C++ newsgroups

Question: Do you know of any good C/C++ mailing lists? I’m a computer science major and I’d like to join one. Answer: I am not aware of any mailing lists but I strongly recommend the newsgroups comp.lang.c++.moderated and comp.std.c++.Both are extremely useful for anyone interested in the C++world. Both groups

How portable is C++?

Question: How portable is C++ as a programming language (in terms of different operating systems andhardware)? Answer: C++ is a fairly new language that until recently did not specify anystandard library components. The draft ANSI/ISO specifies theprecise definition of the language and its libraries. So once all vendors become 100

Using self-defined libraries

Question: I am using Borland Turbo C++ 3.1 and I can’t figureout how to use my self-defined libraries. I’ve used”#include” but I get an error every time I try touse a function from that library. I have a book that shows me how to write the implementation and defenition files,

What to do with overload arguments

Question: Which arguments do you receive when you overload . and -> , and what do you do with the arguments? I know that for overloading [] you receive the index. How about . and -> ? Answer: First, the . operator cannot be overloaded. If it could be, there

What is pure virtual function?

Question: Can you explain and give me examples of pure virtual function? What is the difference between pure virtual function and virtual function? Answer: A pure virtual function is a virtual member function of a class that hasno implementation. When writing classes from which people will inherit, it is important

No more posts to show