C++ VC 2009-10-28 08:56:07 阅读242 评论0 字号:大中小
目的:在data.txt(config.ini)中存储各种程序配置信息(文件存储形式)
CString m_write;
char *str;
str = m_write.GetBuffer(m_write.GetLength());//将字符串转换为字符指针形式
CStdioFile file("data.txt",CFile::modeCreate|CFile::typeText|CFile::modeReadWrite);
file.WriteString(str);
m_write.ReleaseBuffer();
file.Close();
使用空格间隔每行string,使用下列方式,截段字符串,获取信息。
CString x = "abc def ghi jkld";
CString temp,a,b,c,d;
a =x.Left(x.FindOneOf(" "));
temp = x.Mid(x.FindOneOf(" ")+1);
b = temp.Left(temp.FindOneOf(" "));
temp = temp.Mid(temp.FindOneOf(" ")+1);
c = temp.Left(temp.FindOneOf(" "));
temp = temp.Mid(temp.FindOneOf(" ")+1);
temp.TrimLeft();
d= temp;
cout<<"1."<<a<<endl;
cout<<"2."<<b<<endl;
cout<<"3."<<c<<endl;
cout<<"4."<<d<<endl;