dave said:
I would apprecaite the followinghelp;
I need to pass a TCHAR * s = foo*.* \0 *h\0" to CString operator,
There is no such thing as 'TCHAR' or 'CString' in standard C++.
That is, you have selected the wrong forum to post your article
to. If you had asked how to create a corresponding
'std::basic_string', the answer would be simple:
/**/ char const cliteral[] = "foo*.+ \0 *h\0";
/**/ std::string s1(begin(cliteral), (end(cliteral) - 1));
/**/ wchar_t const wliteral[] = L"foo*.+ \0 *h\0";
/**/ std::wtring s1(begin(wliteral), (end(wliteral) - 1));
with suitable definitions of 'begin()' and 'end()', e.g. these:
/**/ template <typename T, int sz>
/**/ T* begin(T(&a)[sz]) { return a; }
/**/ template <typename T, int sz>
/**/ T* end(T(&a)[sz]) { return a + sz; }
Note that the arrays are one character too big: string literals
contain an additional terminating null character. Thus, you
need to substract "1" from the end to obtain a proper past the
end iterator.
BTW, note that the type of string literals is 'char const*' or,
for wide characters, 'wchar_t const*' (note the "const"). The
reason you can assign a string literal to a pointer to non-const
characters is to provide backward compatibility. You should not
rely on this assignment and a good compiler should warn about it
in default mode.