April 22, 1998

C++ equivilant of Basic MID$

Question: I need to test for a certain char in a char array.For example, in BASIC I would have: if mid$(string,1,1) = “`” then blah blah blah…. How would I do this in C/C++? Note: I’m still new to C++ 😛 Compiler == Turbo C++ 3.0(Dos) Answer: Normally, you could

Sorting in a ListView

Question: I would like to know how to program a Custom Sort procedure on a ListView in Borland’s C++ Builder. Answer: Normally, the ListView control will sort items automatically for you. However, it may not sort them in the order you want. For example, alphabetically, “10/1/98” comes before “4/1/98,” but

Return type _Cdecl

Question: I have seen that in many of the header files in C++ the return type is _Cdecl. For example, in complex.h, we have the following: friend complex _Cdecl acos(complex&) What does _Cdecl mean, and how can we use it in our programs? Answer: Although it may look like it,

Quick sort

Question: I have pseudocode for a quick sort. I know how to implement it in Pascal. Is there simple code for quick sort in C++? How can I find other simple algorithms like this? My teacher says they have all been written many times over! Answer: Probably picking up a

External file execution

Question: How can I code a Visual C++ program that will execute a DOS bat file? Or any other executable file, for that matter? Answer: Use the system() function. This function is part of the standard run-time library and takes the name of the command or file you want to

Functions and parameters

Question: I know this may sound like a dorky question, but can you explain to me?as if I were a little kid?what are functions, and why and how are parameters used? Answer: Well, okay son. In the first days of programming, programs simply started at the top and ended at

Pointers to member functions

Question: I am having lots of trouble calling a class member function pointer that is declared within the same class. So far the following compiles: class testClass {public: void (testClass::*ptr)(); testClass(); // constructorprivate: void testFunc();}testClass:testClass() { ptr = &(testClass::testFunc);}; Now I cannot find a way of calling this function pointer

Integer lengths

Question: What function gives the actual length of an integer or long integer? For instance, 8 is 1 long, 12345 is 5 long, etc. Answer: Use the sizeof() operator to give the size of any variable.

Performance—C vs C++

Question: What are the performance tradeoffs of using C++ instead of C? Are there any ways of overcoming these tradeoffs? Answer: In general, C++ is every bit as efficient as C is. The problem (if you want to call it that) is that C++ can do a lot of things

No more posts to show