-1

I wanted to understand the use of _T("xyz") in the code below:

#include<CString.h>
int main()
{
   uint32_t xyz = 15;
   LPCSTR Desc = "xyz value is : ";
   CString Value;
   Value = (LPCSTR)Desc + _T("xyz");
}

Will the above code display:

xyz value is : 15

or

xyz value is : xyz

How to display -

xyz value is : 15

C A Anusha
  • 37
  • 7

2 Answers2

1

The _T macro is used to simplify transporting code for international uses.

See https://msdn.microsoft.com/en-us/library/c426s321.aspx for more information.

Neil Stoker
  • 284
  • 3
  • 16
0

You probably want this:

uint32_t xyz = 15;
LPCWSTR Desc = L"xyz value is : %d";
CString Value;
Value.Format(Desc, xyz);

Forget about the _T macro. What makes you think you should use it?

Or maybe you need this:

uint32_t xyz = 15;                // integer variable containing the number 15
CString stxyz;                    // CString variable
stxyz.Format(L"%d", xyz);          // stxyz contains "15" now

LPCWSTR Desc = L"xyz value is : ";  // Desc points to the string literal "15"

CString Value = Desc + stxyz;     // Value contains concatenation of Desc and stxyz
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • I have two string for which I need to concatenate – C A Anusha Oct 17 '18 at 12:17
  • @CAAnusha OK, so you need to transform `xyz` into string first. BTW `"XYZ"` is a string literal, its content is in no way related to the identifier `xyz`. – Jabberwocky Oct 17 '18 at 12:18
  • I thought that is used to convert any non-string value to string – C A Anusha Oct 17 '18 at 12:21
  • _I thought that is used to convert any non-string value to string_: absolutely not. You need to learn at least the basics of C++ to understand why my answers work. – Jabberwocky Oct 17 '18 at 12:22
  • I am using a user defined datatype basically a union instead of uint32_t .. How should I store in string then? – C A Anusha Oct 17 '18 at 12:30
  • I am getting below error Severity Code Description Project File Line Suppression State Error C2664 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *' – C A Anusha Oct 17 '18 at 12:31
  • Replace `LPCSTR` with `LPCWSTR` and replace `"xyz value is : "` with `L"xyz value is : "`. – Jabberwocky Oct 17 '18 at 12:34