下面记录一些常见的操作代码
更多可以查看https://blog.youkuaiyun.com/kaida1234/article/details/51150420
int iterations = atoi(argv[2]); //传递参数的格式转化为int型
if (temp.Right(11) == CString("Section: 1")) //若CString类的temp的右边11位字符串内容是Section: 1;
if (-1 != temp.Find("Section")//如果在字符串temp中找不到Section,则函数find会返回-1;
shuchu.Format("本文件中共有%d个截面", m_MaxNumSection)//将整型数字整合到CString型的shuchu字符串中去;
((CButton*)GetDlgItem(IDC_CHECK1))->SetCheck(0);//设置按钮的状态
GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE);//设置按钮的状态
UpdateData(true); //窗体中有一个Edit控件,为这个控件关联了CString类型的变量m_strName; 你在控件中添入内容之后,调用这个函数把你添入的内容传给m_strName这个变量
double x = 0,y=0,z=0; sscanf_s(temp, "%lf%lf%lf", &x, &y, &z);//将CString类型的字符串temp中的对应格式数字赋值给x,y,z;
time = CTime::GetCurrentTime();获得计算机当前的时刻
CString Date = time.Format("%d-%m-%Y");//当前时间格式 19-MAR-2018存进Date
CString Time = time.Format("%H:%M:%S");//当前时间格式 14 : 31 : 09存进Time
temp.Replace("19-MAR-2018", Date);//用CString类型的Date在temp中置换"19-MAR-2018"这个字符串;
CString temp="abcd"; temp.GetAt(2)返回的是第3个字符"c";
temp.Remove(_T('"'));//temp内容是T="try",去除所有双引号
temp.Replace("T=","");//去除T=那么剩下的就是try三个字符了
//temp现在是G01A-66B-230
temp.Delete(0,4); //-66B-230
CString temp2 = temp;
int c = temp.Find(_T('B'));
int d = temp.GetLength();
temp.Delete(c, d - c);
A1 = temp;
int e = temp2.Find(_T('B'));//temp2现在是-66B-230
temp2.Delete(0,e+1);
B1 = temp2;
将CString转化为float数字类型
CString m_addVariable2 = "45";
float Variable2;
Variable2 = atof(m_addVariable2);