关于TEXT()的使用问题

Pokeeeer 2015-09-17 02:34:02

//a.h
bool LoadPicFile(PCWSTR uri, IWICFormatConverter **pConverter);


在加载图片时调用上面的函数:
//.cpp
LoadPicFile(TEXT("..//aa//bb//X.png"), &pConverterX);

这样调用时没问题,可以加载X.png

但是我现在通过宏定义指定路径,方便调用

#define PicFilePath  "....//aa//bb//"

LoadPicFile(TEXT("xxxxxxx"), &pConvertX);


所以TEXT()的参数xxxxxx,需要将PicFilePath与X.png拼接起来。
使用字符串的拼接方法会报错:empression must have class type
应该是那个宏没定义类型。

我想请问,有什么方法可以把PicFilePath与X.png拼接起来,不报错。
...全文
150 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-09-18
  • 打赏
  • 举报
回复
Using Generic-Text Mappings Microsoft Specific —> To simplify code development for various international markets, the Microsoft run-time library provides Microsoft-specific “generic-text” mappings for many data types, routines, and other objects. These mappings are defined in TCHAR.H. You can use these name mappings to write generic code that can be compiled for any of the three kinds of character sets: ASCII (SBCS), MBCS, or Unicode, depending on a manifest constant you define using a #define statement. Generic-text mappings are Microsoft extensions that are not ANSI compatible. Preprocessor Directives for Generic-Text Mappings #define Compiled Version Example _UNICODE Unicode (wide-character) _tcsrev maps to _wcsrev _MBCS Multibyte-character _tcsrev maps to _mbsrev None (the default: neither _UNICODE nor _MBCS defined) SBCS (ASCII) _tcsrev maps to strrev For example, the generic-text function _tcsrev, defined in TCHAR.H, maps to mbsrev if MBCS has been defined in your program, or to _wcsrev if _UNICODE has been defined. Otherwise _tcsrev maps to strrev. The generic-text data type _TCHAR, also defined in TCHAR.H, maps to type char if _MBCS is defined, to type wchar_t if _UNICODE is defined, and to type char if neither constant is defined. Other data type mappings are provided in TCHAR.H for programming convenience, but _TCHAR is the type that is most useful. Generic-Text Data Type Mappings Generic-Text Data Type Name SBCS (_UNICODE, _MBCS Not Defined) _MBCS Defined _UNICODE Defined _TCHAR char char wchar_t _TINT int int wint_t _TSCHAR signed char signed char wchar_t _TUCHAR unsigned char unsigned char wchar_t _TXCHAR char unsigned char wchar_t _T or _TEXT No effect (removed by preprocessor) No effect (removed by preprocessor) L (converts following character or string to its Unicode counterpart) For a complete list of generic-text mappings of routines, variables, and other objects, see Appendix B, Generic-Text Mappings. The following code fragments illustrate the use of _TCHAR and _tcsrev for mapping to the MBCS, Unicode, and SBCS models. _TCHAR *RetVal, *szString; RetVal = _tcsrev(szString); If MBCS has been defined, the preprocessor maps the preceding fragment to the following code: char *RetVal, *szString; RetVal = _mbsrev(szString); If _UNICODE has been defined, the preprocessor maps the same fragment to the following code: wchar_t *RetVal, *szString; RetVal = _wcsrev(szString); If neither _MBCS nor _UNICODE has been defined, the preprocessor maps the fragment to single-byte ASCII code, as follows: char *RetVal, *szString; RetVal = strrev(szString); Thus you can write, maintain, and compile a single source code file to run with routines that are specific to any of the three kinds of character sets. See Also Generic-text mappings, Data type mappings, Constants and global variable mappings, Routine mappings, A sample generic-text propgram END Microsoft Specific
ooolinux 2015-09-17
  • 打赏
  • 举报
回复
这样是否可行: const string path="....//aa//bb//; LoadPicFile(TEXT((path+"X.png").c_str()), &pConvertX);
赵4老师 2015-09-17
  • 打赏
  • 举报
回复
#define PicFilePath  TEXT("..\\aa\\bb\\")
LoadPicFile(PicFilePath TEXT("X.png"), &pConvertX);
Pokeeeer 2015-09-17
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
C++ String Literals A string literal consists of zero or more characters from the source character set surrounded by double quotation marks ("). A string literal represents a sequence of characters that, taken together, form a null-terminated string. ………… "\005five" // Use octal constant. "\x05" "five" // Use string splicing.
能直接点说下问题吗,赵老师?
Pokeeeer 2015-09-17
  • 打赏
  • 举报
回复
引用 1 楼 fefe82 的回复:
TEXT(PicFilePath "X.png")
报错了。。 error C2308: concatenating mismatched strings
Pokeeeer 2015-09-17
  • 打赏
  • 举报
回复
引用 1 楼 fefe82 的回复:
TEXT(PicFilePath "X.png")
真的是这样? 我之前试过好多种形式,只有这种没报错,但是因为现在不能调试,没敢确认! 哈哈,没这么用过,太小白了! 再请教个问题。。。 在C++中表示路径时,分别什么时候用“//” 和“\\”,我在工程中看到这两种都有用的。。
赵4老师 2015-09-17
  • 打赏
  • 举报
回复
C++ String Literals A string literal consists of zero or more characters from the source character set surrounded by double quotation marks ("). A string literal represents a sequence of characters that, taken together, form a null-terminated string. Syntax string-literal : "s-char-sequenceopt" L"s-char-sequenceopt" s-char-sequence : s-char s-char-sequence s-char s-char : any member of the source character set except the double quotation mark ("), backslash (\), or newline character escape-sequence C++ strings have these types: Array of char[n], where n is the length of the string (in characters) plus 1 for the terminating '\0' that marks the end of the string Array of wchar_t, for wide-character strings The result of modifying a string constant is undefined. For example: char *szStr = "1234"; szStr[2] = 'A'; // Results undefined Microsoft Specific In some cases, identical string literals can be “pooled” to save space in the executable file. In string-literal pooling, the compiler causes all references to a particular string literal to point to the same location in memory, instead of having each reference point to a separate instance of the string literal. The/Gf compiler option enables string pooling. END Microsoft Specific When specifying string literals, adjacent strings are concatenated. Therefore, this declaration: char szStr[] = "12" "34"; is identical to this declaration: char szStr[] = "1234"; This concatenation of adjacent strings makes it easy to specify long strings across multiple lines: cout << "Four score and seven years " "ago, our forefathers brought forth " "upon this continent a new nation."; In the preceding example, the entire string Four score and seven years ago, our forefathers brought forth upon this continent a new nation. is spliced together. This string can also be specified using line splicing as follows: cout << "Four score and seven years \ ago, our forefathers brought forth \ upon this continent a new nation."; After all adjacent strings in the constant have been concatenated, the NULL character, '\0', is appended to provide an end-of-string marker for C string-handling functions. When the first string contains an escape character, string concatenation can yield surprising results. Consider the following two declarations: char szStr1[] = "\01" "23"; char szStr2[] = "\0123"; Although it is natural to assume that szStr1 and szStr2 contain the same values, the values they actually contain are shown in Figure 1.1. Figure 1.1 Escapes and String Concatenation Microsoft Specific The maximum length of a string literal is approximately 2,048 bytes. This limit applies to strings of type char[] and wchar_t[]. If a string literal consists of parts enclosed in double quotation marks, the preprocessor concatenates the parts into a single string, and for each line concatenated, it adds an extra byte to the total number of bytes. For example, suppose a string consists of 40 lines with 50 characters per line (2,000 characters), and one line with 7 characters, and each line is surrounded by double quotation marks. This adds up to 2,007 bytes plus one byte for the terminating null character, for a total of 2,008 bytes. On concatenation, an extra character is added to the total number of bytes for each of the first 40 lines. This makes a total of 2,048 bytes. (The extra characters are not actually written to the string.) Note, however, that if line continuations (\) are used instead of double quotation marks, the preprocessor does not add an extra character for each line. END Microsoft Specific Determine the size of string objects by counting the number of characters and adding 1 for the terminating '\0' or 2 for type wchar_t. Because the double quotation mark (") encloses strings, use the escape sequence (\") to represent enclosed double quotation marks. The single quotation mark (') can be represented without an escape sequence. The backslash character (\) is a line-continuation character when placed at the end of a line. If you want a backslash character to appear within a string, you must type two backslashes (\\). (SeePhases of Translation in the Preprocessor Reference for more information about line continuation.) To specify a string of type wide-character (wchar_t[]), precede the opening double quotation mark with the character L. For example: wchar_t wszStr[] = L"1a1g"; All normal escape codes listed in Character Constants are valid in string constants. For example: cout << "First line\nSecond line"; cout << "Error! Take corrective action\a"; Because the escape code terminates at the first character that is not a hexadecimal digit, specification of string constants with embedded hexadecimal escape codes can cause unexpected results. The following example is intended to create a string literal containing ASCII 5, followed by the characters five: \x05five" The actual result is a hexadecimal 5F, which is the ASCII code for an underscore, followed by the characters ive. The following example produces the desired results: "\005five" // Use octal constant. "\x05" "five" // Use string splicing.
Pokeeeer 2015-09-17
  • 打赏
  • 举报
回复
真的是这样? 我之前试过好多种形式,只有这种没报错,但是因为现在不能调试,没敢确认! 哈哈,没这么用过,太小白了!
fefe82 2015-09-17
  • 打赏
  • 举报
回复
TEXT(PicFilePath "X.png")

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧