Convert char to TCHAR* argv[]

北城余情 提交于 2019-12-18 08:56:21

问题


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);

回答1:


One way to do is:

char a[] = "Hello world";
USES_CONVERSION;
TCHAR* b = A2T(a);



回答2:


/*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;
   }


来源:https://stackoverflow.com/questions/2652643/convert-char-to-tchar-argv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!