Format data using format string 'pszFormat'

Here is a section code in cstring.h to format data.
It seems to be very complicated for me (just knowing basic about C and C++).
Could you tell me what should I learn in order to understand this?
Some links also will be great.
I learned about template last week.
1
2
3
4
5
6
7
8
9
10
11
12
13
// Format data using format string 'pszFormat'
template< typename BaseType, class StringTraits >
inline void __cdecl CStringT<BaseType, StringTraits>::Format(
	_In_z_ _FormatMessage_format_string_ PCXSTR pszFormat,
	...)
{
	ATLASSERT( AtlIsValidString( pszFormat ) );

	va_list argList;
	va_start( argList, pszFormat );
	FormatV( pszFormat, argList );
	va_end( argList );
}
Could anyone give me a link to read up about this?
Well, any help?
why do you want to understand this??
Hi,
I see this format function is used a lot in a program that I am reading. So I need to understand it to be able write similar commands/instructions.
Any help?
It uses C-style variadic functions. See: http://en.cppreference.com/w/cpp/language/variadic_arguments


> So I need to understand it to be able write similar commands/instructions.

As far as possible, avoid writing similar type-unsafe functions in C++; instead use variadic templates.
http://en.cppreference.com/w/cpp/language/parameter_pack
Thanks for the reply!
Variadic arguments allow a function to accept any number of arguments. That seems cool!
Actually, I'd like to know how this function works so that I can use it in my program.

Here is an example of usage in my program:

1
2
Cstring strName;
strName.Format( "string%d", i + 1 );


After this command, strName will be string1, string2,...
(let's say i from 0 to N)
Could you tell me how the function Format do that?
For example, with i =0, it will assign strName = string1.

Topic archived. No new replies allowed.