The following is a loose collection of notes concerning issues I have found less than obvious in using the microsoft visual studio IDE with microsoft visual c++ compiler.
1. Wide char (unicode) verses single-byte char. I mostly don't need wide char, and I don't like the large number of type declarations used in Windows API when often they are a renaming of a standard C++ type. (I can see the reason why they were introduced---to aid future compatibility---but it is a bore learning them). Therefore I like to be able to write a call to MessageBox, for example, like this:
MessageBox(NULL, "There was a problem", "Warning", MB_OK);
I found that visual studio, in its default settings, complained with the compiler error "cannot convert parameter from 'const char *' to 'LPCWSTR'". To solve the problem you can add two type-casts, as in
MessageBox(NULL, (LPCWSTR) "There was a problem", (LPCWSTR) "Warning", MB_OK);
but this is a bore and reduces program readability. To avoid this problem and allow the compiler to accept the first version, you need to tell visual studio not to use a couple of compiler options involving UNICODE. To do this go to project/properties (or alt-F7); in the menu system, and find "configuration properties/general". Then find "character set" in the list in the panel, and set it to "not set". |
2. valarray.min() and max(). When using valarrays I found the visual c++ compiler could not correctly compile these STL functions! The reason is that somewhere in the windows stuff there is a definition of some macros called min and max, and the compiler thinks this is what you want! I got around the problem by putting
#undef min
#undef max in a header file. No doubt there are other solutions. |
3. String manipulations. The visual c++ compiler did not allow void myfunc(string s) { blah; } ... string name; myfunc(name + "ab"); name += "ab"; myfunc(name); |