Is there any better alternative for doing string formatting in VC6, with syntax checking before substitution?
Is there any better alternative for doing string formatting in VC6, with syntax checking
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
CStringoffers theFormatmethod forprintf-style formatting, but this isn’t type-safe.For type-safe string formatting you could either use
std::stringstream/std::wstringstreamor the Boost Format library, although these both work with the C++std::basic_stringclass template, and not the MFCCStringclass. I’ve used both of these successfully in VC6.Boost Format is nice because it allows you to use
printf-like syntax, and will throw an exception if the arguments you supply don’t match the format string, whereas string formatting with C++ iostreams tends to make your code quite verbose.Note that you can create a
CStringobject from astd::stringas follows:I hope this helps!