string,QString,opencv,log4cplus与中文

#include <iostream>
#include <opencv2\opencv.hpp>
#include <QtCore/QCoreApplication>
#include "LogHelper.h"

using namespace std;

int main(int argc, char *argv[])
{
    cout << "0.中文" << endl;                // OK
    LOG_INFO("0.中文");                    // OK
    cv::Mat mat = cv::imread("D:/图片.bmp");    // OK

    string s1 = "1.中文";                    // 断点查看:OK
    cout << s1 << endl;                    // OK
    QString qs1(s1.c_str());                // 断点查看:乱码
QString qs2 = QString::fromStdString(s1); // 乱码
   QString qs3 = QString::fromLocal8Bit(s1.c_str()); // OK QString s2 = "2.中文"; // 断点查看:乱码 cout << s2.toStdString() << endl; // 乱码 cout << string(s2.toLocal8Bit()) << endl; // 乱码 QString s3 = QStringLiteral("3.中文"); // 断点查看:OK cout << s3.toStdString() << endl; // 乱码 cout << string(s3.toLocal8Bit()) << endl; // OK return 0; }
#include <iostream>
#include <opencv2\opencv.hpp>
#include <QtCore/QCoreApplication>
#include "LogHelper.h"

#pragma execution_character_set("utf-8")

using namespace std;

int main(int argc, char *argv[])
{
    cout << "0.中文" << endl;            // 乱码
    LOG_INFO("0.中文");                // 乱码
    cv::Mat mat = cv::imread("D:/图片.bmp");    // 打开失败

    string s1 = "1.中文";                // 断点查看:乱码
    cout << s1 << endl;                // 乱码
    QString qs1(s1.c_str());            // 断点查看:OK

    QString s2 = "2.中文";            // 断点查看:OK
    cout << s2.toStdString() << endl;    // 乱码
    cout << string(s2.toLocal8Bit()) << endl;    // OK

    QString s3 = QStringLiteral("3.中文");        // 断点查看:乱码
    cout << s3.toStdString() << endl;        // 乱码
    cout << string(s3.toLocal8Bit()) << endl;    // 乱码

    return 0;
}

 

posted on 2022-03-01 09:14  朱迎春  阅读(178)  评论(0编辑  收藏  举报