Data type conversion of char and TCHAR in VC

Source: Internet
Author: User
Tags sprintf

Char: A basic data type that can hold a single character in the Computer programming language (c, C + +, Java, VFP, etc.).

TCHAR: To satisfy Unicode encoding, the extension of Char, i.e. _t ("str"), represents the TCHAR type

C + + supports two strings, the conventional ANSI encoding (using the "package") and the Unicode encoding (using the L "" package), which corresponds to two sets of string string handlers, such as strlen and Wcslen, for handling two string char and TCHAR types, respectively.

WinNT.h header file:

typedef WCHAR TCHAR, *ptchar;

Indicates that TCHAR and WCHAR belong to the same type

Char sza[100]; ANSI String Buffer

WCHAR szw[100]; Unicode String Buffer

Normal Sprintf:all strings are ANSI

sprintf (Sza, "%s", "ANSI Str");

Converts Unicode string to ANSI

sprintf (Sza, "%s", L "Unicode Str");

Normal Swprintf:all strings are Unicode

swprintf (szw,l "% s", L "Unicode Str");

Converts ANSI string to Unicode

swprintf (szw,l "%s", "ANSI Str");

Note: The use of uppercase s and lowercase s

Application instance: Invoking the start MSC program through the system function program

void 

Wsus::onbnclickedok ()      
{
    CString strpath = NULL;     Application path String (TCHAR)
    char strchar[256];  Application path String (char)

    M_CUSTOMEDIT.GETWINDOWTEXTW (strpath);   Gets the path stored to the strpath

    strpath.replace (_t ("\"), _t ("\\\\"));	Replace "\" in strpath with "\", note the translator
    //sprintf (Strchar, "%s", "Mmc.exe", strpath);        TCHAR convert char type
    sprintf (strchar, "mmc.exe \%s\" ", strpath);        TCHAR converts char type

    MessageBox (strpath, _t ("title"));
    System (STRCHAR);                        System function calls start MSC program

    //winexec ((LPCSTR) _bstr_t (strpath), sw_show);   Calling EXE program
}
Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.