4

How can I input text into TCHAR* argv[]?

OR: How can I convert from char to TCHAR* argv[]?

char randcount[] = "Hello world";

TCHAR* argv[];

argv = convert(randcount);
SamB
  • 9,039
  • 5
  • 49
  • 56
Sijith
  • 3,740
  • 17
  • 61
  • 101
  • TCHAR* argv[]=_T("HelloWorld"); Its showing error error C2440: 'initializing' : cannot convert from 'const char [134]' to 'TCHAR *[]' – Sijith Apr 16 '10 at 12:06
  • You are missing " at the beginning :-) apart from the `TCHAR* argv[]` is an array of TCHAR pointers and you are trying to assign a string to it. You need to something like this: `TCHAR* argv[10]; argv[0]=_T("HelloWorld");` – Naveen Apr 16 '10 at 12:09
  • i gave my code like this TCHAR* ptszFirstInFile = _T("sample1.asf") ; TCHAR* ptszSecondInFile = _T("sample2.asf") ; TCHAR* ptszOutFile = _T("xxxx.asf") ; NOw getting error cannot convert from 'const char [12]' to 'TCHAR *' – Sijith Apr 16 '10 at 13:14

2 Answers2

7

One way to do is:

char a[] = "Hello world";
USES_CONVERSION;
TCHAR* b = A2T(a);
Naveen
  • 74,600
  • 47
  • 176
  • 233
0

/*This code did TCHAR in my project without A2T or any other converters. Char text is a some kind of array. So we can take letters one by one and put them to TCHAR. */

    #include <iostream>
   TCHAR* Converter(char* cha)    
   {
       int aa = strlen(cha);
       TCHAR* tmp = new TCHAR[aa+1];
       for(int i = 0; i< aa+1; i++)
          {
            tmp[i]=cha[i];
          }
       return tmp;
   }

   int main()
   {
       char* chstr= new char[100];
       chstr = "char string";
       TCHAR* Tstr = new TCHAR[100];
       //Below function "Converter" will do it
       Tstr = Converter(chstr);
       std::cout<<chstr<<std::endl;
       std::wcout<<Tstr<<std::endl;
   }
  • Can you please explain your code a bit so others can understand? –  May 24 '17 at 22:34
  • This code did TCHAR in my project without A2T or any other converters. Char text is a some kind of array. So we can take letters one by one and put them to TCHAR. – Max Barannyk Aug 20 '17 at 16:20
  • Can you put it in your answer, please? –  Aug 21 '17 at 00:51