我想从 CString 中提取 float ,格式如下:(示例提取 22.760348)
Incidence_angle(inc)[deg] :22.760348
基本上我正在读取一个包含一些参数的纯文本文件,我想对这些值执行一些计算。我使用 CStdioFile 对象读取文件并使用 readString 方法提取每一行,如下所示:
CStdioFile result(global::resultFile,CFile::modeRead);
while( result.ReadString(tmp) )
{
if(tmp.Find(L"Incidence_angle(inc)[deg]") != -1)
{
//extract value of theeta i here
// this is probably wrong
theeta_i = _tscanf(L"Incidence_angle(inc)[deg] :%f",&theeta_i);
}
}
我尝试使用 scanf,因为我想不出任何其他方法。
如果这个问题看起来非常基础和愚蠢,我深表歉意,但我已经坚持了很长时间,希望得到一些帮助。
编辑:把我写的proof of concept程序拿出来,造成困惑
最佳答案
假设tmp
是CString
,正确的代码是
CStdioFile result(global::resultFile,CFile::modeRead);
while( result.ReadString(tmp) )
{
if (swscanf_s(tmp, L"Incidence_angle(inc)[deg] :%f", &theeta_i) == 1)
{
// Use the float falue
}
}
关于c++ - 从 CString 中提取 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11935864/