Sorry for being off-topic, but I wonder whether there is a free MFC-like and prefereably platform-independent CString class which contains the Format-method.
I've found a couple of implementations but they were quite lacking and most of them didn't compile at all without modifications (I'm using the DevC++ IDE / MingW compiler).

Thanks in advance

playmesumch00ns

03-14-2005, 01:49 PM

What exactly does CString's format method do? A good starting point when looking for these sort of algorithms is always the boost libraries: http://www.boost.org/

Vertizor

03-14-2005, 03:21 PM

Google search for STL. Standard Template Library. Cross platform, the namespace is std:: inside is a String class. It has a lot of useful functions, but no it does not have a format function.

You could extend this String class and make your own. It has a function to return a C (as in the language) string pointer (char*). Use that char* in conjunction with sprintf() from the C runtime and you have a nice portable C++ class with formating.

Google sprintf for more info. Works just like MFC's CString::format(), infact CString::format() borrows from sprintf, I wouldn't be surprised it it actually calls sprintf because the arguments are identical. sprintf just takes an additional arugment which is the destination buffer to store the formated string into.

gga

03-14-2005, 09:09 PM

googSorry for being off-topic, but I wonder whether there is a free MFC-like and prefereably platform-independent CString class which contains the Format-method.
I've found a couple of implementations but they were quite lacking and most of them didn't compile at all without modifications (I'm using the DevC++ IDE / MingW compiler).

Thanks in advance

Learn the STL. This is a standard library you will find with *every* C++ compiler. The std::string class should offer equivalents to most of the things in MFC and in many cases, in a smarter way.
Unlike the CString class, most STL implementations of std::string are not reference counted strings as the MFC implementation is, but use copy on write, which offers pretty much the same benefits.
The format() function is just printf or sprintf. You can usually do:

like they said, check out the STL, if that doesn't work then check the boost libraries.

MDuffy

03-15-2005, 01:22 AM

I've found the STL to be a flaming pile of poo to actually use, especially when tying together other libraries that are using STL, possibly different versions of STL (xerces + houdini + sgistl (for multimap) + some of the Linux libs, etc, etc.) Plus STL in general requires a lot of typing for doing what should be simple things, is not all that cross-platform in practice (because various compiler writers have created poor implementations of the standard, and the standard has changed over the years), and overall is pretty much impossible to debug.

But that's just me.

Google for FastString. It is a pretty good replacement for the MFC CString class. It has a format call, and is mostly a drop-in replacement for CString. It isn't perfect though, and I had to customize it a lot internally when I used it. I've since written my own string class from scratch (with format and a lot of other useful string manipulation approaches I've seen in various libs), and that's what I currently use in all my code. Easy to view the contents of the string in a debugger, and whenever I need new functionality I can just go in and add it without fuss.

Cheers,
Michael Duffy

dotTom

04-08-2005, 08:30 PM

I've found the STL to be a flaming pile of poo to actually use, especially when tying together other libraries that are using STL, possibly different versions of STL (xerces + houdini + sgistl (for multimap) + some of the Linux libs, etc, etc.) Plus STL in general requires a lot of typing for doing what should be simple things, is not all that cross-platform in practice (because various compiler writers have created poor implementations of the standard, and the standard has changed over the years), and overall is pretty much impossible to debug

STL is awesome. Learning template based meta programming is a great way to take your C++ to the next level, with it you can mix static and dynamic polymorphism, use traits to avoid pointless inheritance etc. Well worth learning. Whilst it's true that older compilers produce template errors that look like line noise modern compilers make a much better job of it. If you want a first class STL implementation take a look at SGI or HP implementations (in that order).

tweeeker

04-10-2005, 12:59 PM

If you go with STL also check out stringstream (#include <sstream>). This offers similar functionallity to sprintf without resorting to char pointers and c functions (which there's nothing wrong with of course).
T

CGTalk Moderation

04-10-2005, 12:59 PM

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.