解决 CodeLite 中文乱码的问题,并支持C++11特性



1. 安装 MinGW Distro (GNU GCC) 或 TDM-GCCClang


2. 安装 CodeLite

3. 运行并配置 CodeLite
CodeLite10

CodeLite20


4. 汉化 CodeLite
下载中文语言包https://github.com/eranif/codelite/tree/master/translations,中文语言包解压后得到zh_CN文件夹,文件夹包含codelite.mo和codelite.po两个文件,将文件夹zh_CN直接复制到CodeLite安装目录下locale文件夹内。
打开CodeLite软件,从菜单【Settings -> Preferences】,选择【Misc -> Encoding Locale】,修改 Locale to use 的值为 zh_CN:Chinese(Simplified) 。
CodeLite30

CodeLite40

CodeLite50


5. 支持处理中文
从菜单【设置 -> 构建设置】进入构建设置页面,选择【编译器 -> MinGW -> 开关】,修改 Debug 和 Source 的值,在其原值的后面加上 -fexec-charset=GBK -finput-charset=UTF-8,然后点【应用】。
CodeLite60
注意一点,步骤4中【文件字体编码】的设置和【-finput-charset】等号后的值应该是相同的,都设置为UTF-8或者GBK(WINDOWS-936),【文件字体编码】指定源代码文件(.c, .h)的编码编码方式,【-finput-charset】则用于告诉GCC编译器源代码文件的编码方式。【-fexec-charset】用于告诉 GCC 编译器处理字符串时采用的编号方式,因为是Windows系统所以选择GBK,如果是Linux系统可以选择UTF-8。

CodeLite65

6. 支持C++11
在【设置 -> 构建设置 -> 编译器 -> MinGW】的右侧将【工具 -> C++编译器】改成 gcc -std=c++14。
(英文版:Setting -> Build Setting -> Tools -> 将 C++ Compiler name 改成 gcc -std=c++14 )

CodeLite70

CodeLite75

7. 测试代码

#include <iostream>
#include <iomanip>      // std::setw
#include <vector>

// 一维数组 输出 杨辉三角形
int main()
{
    using std::cout;
    using std::endl;
    using std::setw;
    using std::vector;

    constexpr size_t Line = 16;
    constexpr unsigned W = 5;

    size_t i, j;
    int n[Line+1];

    cout << "\t\tPascal 三角形\n" << endl;

    cout << setw(W) << (n[1] = 1) << endl;
    for (i = 2; i != Line+1; ++i)
    {
        cout << setw(W) << (n[i] = 1);
        for (j = i-1; j != 1; --j)
            cout << setw(W) << (n[j] += n[j-1]);
        cout << setw(W) << n[1] << endl;
    }
    cout << endl << endl;

    using std::begin;
    using std::end;
    cout << setw(W) << (n[1] = 1) << endl;
    for (int *pl = begin(n)+2; pl != end(n); ++pl)
    {
        cout << setw(W) << (*pl = 1);
        for (int *pr = pl-1; pr != begin(n)+1; --pr)
            cout << setw(W) << (*pr += *(pr-1));
        cout << setw(W) << n[1] << endl;
    }
    cout << endl << endl;

    int nn[Line] = {0}, t;
    bool beg = true;
    for (auto ll : nn)
    {
        beg = true;
        for (auto &mm : nn)
            if (beg && mm == 1)
            {
                cout << setw(W) << (t = mm = 1);
                beg = false;
            }
            else if (mm == 0)
            {
                cout << setw(W) << (mm = 1) << endl;
                break;
            }
            else
            {
                cout << setw(W) << (mm += t);
                t = mm-t;
            }
    }
    cout << endl << endl;


    vector<unsigned> v(Line, 0);

    cout << setw(W) << (v[0] = 1) << endl;
    for (i = 1; i != Line; ++i)
    {
        cout << setw(W) << (v[i] = 1);
        for (j = i-1; j != 0; --j)
            cout << setw(W) << (v[j] += v[j-1]);
        cout << setw(W) << v[0] << endl;
    }
    cout << endl << endl;

    for (auto &ll : v)
    {
        ll = 0;
        beg = true;
        for (auto &mm : v)
            if (beg && mm == 1)
            {
                cout << setw(W) << (t = mm = 1);
                beg = false;
            }
            else if (mm == 0)
            {
                cout << setw(W) << (mm = 1) << endl;
                break;
            }
            else
            {
                cout << setw(W) << (mm += t);
                t = mm-t;
            }
    }
    cout << endl << endl;

    cout << setw(W) << (v[0] = 1) << endl;
    for (vector<unsigned>::iterator it = v.begin()+1; it != v.end(); ++it)
    {
        cout << setw(W) << (*it = 1);
        for (vector<unsigned>::reverse_iterator rit(it); rit != v.rend()-1; ++rit)
            cout << setw(W) << (*rit += *(rit+1));
        cout << setw(W) << *(v.cbegin()) << endl;
    }
    cout << endl << endl;

    return 0;
}

CodeLite80



参考:
https://my.oschina.net/myshow/blog/194971
http://www.itdadao.com/articles/c15a418358p0.html



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM