CString输出文本对齐处理

Posted zeqi1991

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CString输出文本对齐处理相关的知识,希望对你有一定的参考价值。

int HasChineseChar(const CString& str)

    CString content;
    int count = 0;
    for (int i = 0; i < str.GetLength(); i++)
    
        if (str.GetAt(i) > 255)
        
            content += str.GetAt(i);
            count++;
        
    
    return count;


void CMFCApplication1Dlg::OutputLDCaseCoe()

    CStdioFileEx file;
    if (!file.Open(_T("LDCaseCoe.txt"), CFile::modeCreate | CFile::modeWrite | CStdioFileEx::modeWriteUnicode, nullptr))
        return;
    file.WriteString(_T("-------------荷载组合分项系数-------------\\n"));
    std::vector<CString> LDCaseStrVec;
    LDCaseStrVec.push_back(_T("DL"));
    LDCaseStrVec.push_back(_T("地面堆载"));
    LDCaseStrVec.push_back(_T("覆土荷载"));
    LDCaseStrVec.push_back(_T("侧向土压力(低)"));
    LDCaseStrVec.push_back(_T("水压力(低)"));
    LDCaseStrVec.push_back(_T("侧向土压力(常)"));
    LDCaseStrVec.push_back(_T("LL[专用]"));
    LDCaseStrVec.push_back(_T("LL1"));
    LDCaseStrVec.push_back(_T("LL2"));
    LDCaseStrVec.push_back(_T("水浮力"));
    LDCaseStrVec.push_back(_T("EX"));
    LDCaseStrVec.push_back(_T("EY"));
    LDCaseStrVec.push_back(_T("SOIL"));
    //随机数
    std::default_random_engine e;
    std::uniform_real_distribution<double> u(0, 1);
    e.seed(10);

    std::vector<int> spaceLengthVec;
    CString str;
    for (size_t i = 0; i < LDCaseStrVec.size(); i++)
    
        CString stemp = LDCaseStrVec[i];
        CString result;
        result.Format(_T("     %s"), stemp);
        str += result;
        int count = HasChineseChar(result);
        int length = result.GetLength();
        if (count > 0)
            length += count;
        spaceLengthVec.push_back(length);
    
    str += _T("\\n");
    file.WriteString(str);

    str = _T("");
    for (int i = 0; i < 10; i++)
    
        for (size_t j = 0; j < LDCaseStrVec.size(); j++)
        
            CString temp;
            temp.Format(_T("%%%d.2f"), spaceLengthVec[j]);
            CString result;
            double randomValue = u(e);
            result.Format(temp, randomValue);
            str += result;
        
        str += _T("\\n");
        file.WriteString(str);
    
    file.Close();

创作打卡挑战赛 赢取流量/现金/CSDN周边激励大奖

以上是关于CString输出文本对齐处理的主要内容,如果未能解决你的问题,请参考以下文章

CString输出文本对齐处理

C++:浮力程序未按计划输出

您能将关于abaqus如何输出荷载位移曲线步骤说的详细点么?我是新手~急~~~~~

pandas格式化输出文本-excel篇

格式化输出字符串,右对齐

通过控制台对齐文本输出?