|
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();
}
[code]https://blog.csdn.net/zeqi1991/article/details/124782095?spm=1001.2014.3001.5502[/code] |
|