Update September 27, 2008: With CMarkup release 10.0 things have gotten simpler than ever. Using STL strings in Visual C++ has been streamlined, and for other compilers CMarkup defaults to STL strings so you don't need to do anything but add CMarkup to your project and go. See Unified CMarkup for STL and MFC.

Pass STL string variables directly into the constant string (MCD_CSTR) arguments of the CMarkup methods, no need to explicitly add the c_str() method.

CMarkup with STL has been tested on Dev-C++, OSX XCode, and Visual C++ Express 2005 and 2008.

Using CMarkup with STL

Just copy Markup.cpp and Markup.h into your C++ project. In Visual C++ the are a couple of additional steps to be aware of. To use STL strings in VC++, you must put MARKUP_STL in your project defines. For VC++ projects that use precompiled headers you will need to turn off precompiled headers individually for Markup.cpp (see Pre-compiled Header Issue).

For STL users moving to release 9.0 from previous releases, use the "CMarkup" class name instead of "CMarkupSTL" and include Markup.cpp/.h in your project, not MarkupSTL.cpp/.h!

STL stands for Standard Template Library, a set of C++ classes standardized across a number of C++ compilers for different platforms. There are often small inconsistencies in the various implementations of STL, so you cannot assume your source code will immediately compile with every STL implementation. As on any platform, CMarkup has no warranty and in any project it is the responsibility of the developer who uses it.

All of the sample code and documentation about CMarkup applies equally to both MFC and STL usage except where noted. Although most of the CMarkup examples use CString, they will also work equally with std::string. What follows are some experiences with the STL version on various platforms and other STL specific information.


comment posted Can I use CMarkup in Linux?

zhuzl 28-Jun-2007

I am a student of BUAA; our lab uses Linux. Can I use CMarkup in Linux?

Yes you can. Use STL strings and put MARKUP_STL in your project defines. The STL std::string class comes with most C++ compilers, and Markup.h will #include <string> if you define MARKUP_STL.


comment posted Unresolved external symbol __endthreadex

Joachim 20-Sep-2011

I created a complete new project, which simply prints "Hello world" on the console (not MFC).

  • 1. I added "markup.h" to the project. Program still running.
  • 2. I included "markup.h" in the active project, #include "markup.h". Program still running.
  • 3. I add "markup.cpp" to the project (still not using any xml operations). I got the following errors:
  • nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) bereits in LIBCD.lib(dbgdel.obj) definiert
    nafxcwd.lib(thrdcore.obj) : error LNK2001: Nichtaufgeloestes externes Symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: Nichtaufgeloestes externes Symbol __beginthreadex
    Debug/Test.exe : fatal error LNK1120: 2 unaufgeloeste externe Verweise

    In Visual Studio, CMarkup defaults to use CString and tries to link in its dependencies. To use STL std::string instead please define MARKUP_STL in your preprocessor definitions as mentioned above.


    comment posted CMarkup on IPhone

    Geoff 18-Jul-2011

    I am doing an IPhone project, and just included CMarkup in the project to generate the XML for me. I was using the Apple NSXMLParser - but it was so slow... I just did some xml parsing on the iphone with CMarkup and all went fine. Xcode 3.2.6

    Archived experiences before release 9.0

    Notes on previous versions of CMarkup remain here in case they can illuminate current issues that arise such as with additional new compilers.

    All fixes to CMarkupSTL prior to release 9.0, have been brought forward into the STL version of CMarkup in release 9.0.

    CMarkupSTL release 6.0 compiled on Borland C++ Builder 5 (in Windows ME) after a couple of tweaks in MarkupSTL.cpp. These tweaks were brought into subsequent releases of CMarkup.

    In CMarkup release 6.0 and earlier, you have to remove the #include "stdafx.h" (it is gone in release 6.1). Then, cast the first argument in the strchr call to char* because Borland apparently doesn't have a strchr(const char*,int) version of this function. There were about 6 warnings due to the STL size type being unsigned in Borland and signed in Microsoft. Casting the complaining string methods and members to int in MarkupSTL.cpp quieted the warnings: e.g. (int)string::npos and (int)m_strDoc.length().


    comment posted CMarkupSTL on unix

    Wim Bokkers 29-Jan-2002

    When compiling the STL version of CMarkup on SGI IRIX 6.5 (Unix), the itoa() function is not recognized, since it is not ANSI C!

    In release 6.2 and before, CMarkupSTL used the itoa function which is not available on some platforms. In release 6.3 and later, sprintf is used instead.


    comment posted Re: G++ Compile Errors

    Dharmesh 9-Sep-2002

    I have CMarkupSTL now working on G++ under Linux. Other than including <stdio.h>, there was no other change that had to be made.

    According to Dharmesh and other testing by Tobias, CMarkupSTL works on Linux. Prior to release 6.4 you needed to add #include <stdio.h> to the top of MarkupSTL.cpp, but it has since been included.


    comment posted Codewarrior 7.1 on Palm OS

    Gabriel 14-Jan-2003

    I work under Codewarrior 7.1. The target platform is a Visor Platinum running Palm OS 3.5. The steps I took are the following:

  • 1. I used the CMarkupSTL class, which makes use of the (somewhat) limited Metrowerks Standard Library (MSL).
  • 2. Remove all references to MSVC++, by declaring the macro MSVC_VERSION and protecting all pertinent code with an #ifdef MSVC_VERSION. The macro is undefined for Palm OS, hence the effect of removing the code.
  • 3. Replaced all references to the string functions in the standard library with the StringMgr methods, since MSL does not support strings.
  • 4. Replaced the references to <stdio.h> with PalmTypes.h, since stdio.h is not supported by MSL.
  • 5. Disabled (as described in step 2) the Load and Save methods, which do not apply to Palm OS.
  • On this Palm OS platform int is only a 16 bit integer, so it is recommended you change all occurences of int to long. Especially in the Developer version's DecodeBase64 function where it was causing an overrun resulting in a 00 every 2 bytes.


    comment posted strnicmp in CMarkupSTL V8.0

    Frank 27-Jul-2005

    I have problems with the function Match in struct TokenPos. On Windows I get following linker error (did not appear with V7.3)

    MarkupSTL.obj : error LNK2019: unresolved external symbol _strnicmp
    referenced in function "public: bool __thiscall
    CMarkupSTL::TokenPos::Match(char const *)"
    Release/filename.dll : fatal error LNK1120: 1 unresolved externals

    If I use _strnicmp instead of strnicmp it works. We use VC6 and VC7.1. In both cases and with different SDK environments the problem appears.

    It turns out that strnicmp (like stricmp, ignore case string comparison) is not part of standard C and in different compilers is made available with different names. Unix and Mac compilers (and even Borland C++ Builder for Windows) seem to have strnicmp, while Turbo C and Watcom C have strncmpi.

    Microsoft seems to be the only one that has _strnicmp with an underscore. But the strnicmp function without underscore is available in Visual C++ unless __STDC__ is defined or you don't link with oldnames.lib. The test builds for CMarkupSTL in Visual Studio 6.0 and .Net work without the underscore so this issue was not discovered before 8.0 was released. Prior to release 8.0 this was unlikely to be encountered because ignoring case was not a runtime option and very few users compiled with MARKUP_IGNORECASE defined.

    If strnicmp is not available in your build, you probably have an alternative function name such as _strnicmp or strncmpi with the exact same arguments. You can probably define it in your project preprocessor definitions (i.e. -Dstrnicmp=_strnicmp), or above where you include MarkupSTL.h using one of these forms:

    #define strnicmp _strnicmp
    #define strnicmp(s1,s2,n) _strnicmp((s1),(s2),(n))

    Or just replace the function call itself inside MarkupSTL.h.


    comment posted CMarkup purely C++ not using MFC

    Do Xuan Dien 23-Mar-2006

    My project is pure C++, not using MFC. There are some pure C++ xml parsers, but I'm really interested in CMarkup. I don't know how to convert CMarkup so that I can use it in my project.

    If by "pure" C++ you mean to include STL strings then the STL version should be adequate.

    Update April 1, 2007: Beginning with CMarkup release 9.0, for the STL version you use Markup.cpp/.h (not MarkupSTL.cpp/.h) and define MARKUP_STL.


    comment posted STL and UTF-16

    Patrik 05-Apr-2006

    It doesn't look like the STL version of the parser supports UTF-16. Are you planning to release such a version? We would like to avoid MFC if possible.

    Update April 1, 2007: CMarkup release 9.0 introduces support for STL/UNICODE, for Visual C++ out of the box, and for other C++ compilers as well by setting some defines.

    I'm guessing you want to use STL with Visual C++ but without MFC, so you want to use the VC++ wide string functions and defines. This is supported in release 9.0.


    comment posted UNICODE version of MarkupSTL

    Bent 20-Apr-2006

    we would like a pure C++ [UNICODE] STL version

    Update April 1, 2007: CMarkup release 9.0 introduces UNICODE support for the STL version of CMarkup.

    See also UNICODE ATL CMarkup - Without MFC for another way of avoiding MFC in a wide string build.