【问题标题】:Convert char to TCHAR* argv[]将 char 转换为 TCHAR* argv[]
【发布时间】:2010-04-16 11:51:36
【问题描述】:

如何在TCHAR* argv[] 中输入文字?

或者:如何从char 转换为TCHAR* argv[]

char randcount[] = "Hello world";

TCHAR* argv[];

argv = convert(randcount);

【问题讨论】:

  • TCHAR* argv[]=_T("HelloWorld");它显示错误 error C2440: 'initializing' : cannot convert from 'const char [134]' to 'TCHAR *[]'
  • 你在开头缺少 " :-) 除了 TCHAR* argv[] 是一个 TCHAR 指针数组,你正在尝试为它分配一个字符串。你需要这样的东西:@987654326 @
  • 我给了我这样的代码 TCHAR* ptszFirstInFile = _T("sample1.asf") ; TCHAR* ptszSecondInFile = _T("sample2.asf") ; TCHAR* ptszOutFile = _T("xxxx.asf") ;现在出现错误无法从 'const char [12]' 转换为 'TCHAR *'

标签: visual-c++ argv tchar


【解决方案1】:

一种方法是:

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

【讨论】:

  • #include "atlstr.h"
【解决方案2】:

/*此代码在我的项目中执行 TCHAR,没有 A2T 或任何其他转换器。字符文本是某种数组。这样我们就可以一个一个地取字母,然后放到 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;
   }

【讨论】:

  • 您能否解释一下您的代码以便其他人理解?
  • 这段代码在我的项目中进行了 TCHAR,没有 A2T 或任何其他转换器。字符文本是某种数组。这样我们就可以一个一个地取字母,然后放到 TCHAR 中。
  • 你能把它放在你的答案中吗?
猜你喜欢
  • 2013-10-18
  • 2018-01-14
  • 2019-01-05
  • 2011-11-02
  • 2010-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多