C + + vs.net setting UTF8 characters

Source: Internet
Author: User

1. Change main.cpp to Utf-8 encoding by clicking Main.cpp and selecting the Advanced Save option, menu file. "All source code is converted to uft-8."

2, in your main function, set the following code, the perfect solution to qt5 Chinese garbled

Msc_ver is a built-in macro for the MSVC compiler that defines the version of the compiler. Here are some compiler versions of the _msc_ver values

MS VC + + 10.0 _msc_ver = 1600 "VC2010"

MS VC + + 9.0 _msc_ver = 1500 "VC2008"

MS VC + + 8.0 _msc_ver = 1400 "VC2005"

MS VC + + 7.1 _msc_ver = 1310

MS VC + + 7.0 _msc_ver = 1300

MS VC + + 6.0 _msc_ver = 1200

MS VC + + 5.0 _msc_ver = 1100

#include "Testchinese2.h"

#include <QtWidgets/QApplication>

#include <QDebug>

The code must be: UTF-8 (BOM)

QT version higher than or equal to Qt5,vs version is higher or equals VS2010

#if _msc_ver >= 1600

#pragma execution_character_set ("Utf-8")

#endif

int main (int argc, char *argv[])

{

Qapplication A (argc, argv);

QT version less than QT5

#if qt_version < Qt_version_check (5,0,0)

VS version Less than VS2010

#if defined (_msc_ver) && (_msc_ver < 1600)

QTEXTCODEC::SETCODECFORTR (Qtextcodec::codecforname ("GBK"));

#else

QTEXTCODEC::SETCODECFORTR (Qtextcodec::codecforname ("UTF-8"));

#endif

#endif

TestChinese2 W;

W.show ();

Qdebug () << "Hello, 333";

return A.exec ();

}

C + + vs.net setting UTF8 characters

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.