Re: How to use "quote" in TEXT(quote) by Ulrich
Ulrich
Thu Feb 22 03:25:49 CST 2007
I.You wrote:
> I'd like to change "quote" in TEXT(quote), i.e. for example,
>
> char *temp = "filename0";
Note: the conversion of a string literal to a non-const char pointer is only
supplied for backward compatibility with C and deprecated. Using it to
modify things (like you do below) is an error anyway, consider using a
temporary array.
> for(i=0; i<10; i++) {
> ....
> function(TEXT(temp), ...);
> filename[8] += 1;
> ....
>
> This code will be an error as follow :
> error C2065: 'L_temp' : undeclared identifier
Take a look at the TEXT macro. The only thing it does is prefix L when
_UNICODE is defined and leave the string as it is otherwise, so it conforms
to TCHAR. However, this is a preprocessor macro and not a function,
therefore you can only use it with string literals.
What you should perhaps do is to use TCHAR all the way through:
TCHAR temp[] = TEXT("filename0");
for(...) {
function(temp);
++temp[8];
Also, how about using C++ and then taking the string types it provides? For
TCHAR, I'd suggest
typedef std::basic_string<TCHAR> tstring;
> And without TEXT() function fails due to ERROR_FILE_NOT_FOUND.
Said macro won't change that. I guess there is some other broken code that
makes some assumptions that finally fail.
Uli