c++ - 从 CString 中提取 float

标签 c++ mfc cstring

我想从 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程序拿出来,造成困惑

最佳答案

假设tmpCString,正确的代码是

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/

相关文章:

MFC应用程序突然崩溃

谁能帮我找到这个 C 函数中的错误吗?

objective-c - 如何自定义类似 'stringWithFormat' 的方法?

c++ - Boost::typeof 编译器问题:修改 typeof,使用 decltype 代替

c++ - winapi 从函数的地址中获取损坏的名称

c++ - 使用 C++ 的基本终端输出 - 问题

c++ - 在 C++ 中搜索 CString

c++ - 为什么我用了std::future::get还要加入线程?

c++ - 如何将结果从 Int 更改为 Float 数据类型?

c++ - 如何避免控制台输出有关不支持的操作? (IWebBrowser2,DISP_E_MEMBERNOTFOUND)