WriteOutputValue in C++

WriteOutputValue in C++

本文关键字:C++ in WriteOutputValue      更新时间:2023-10-16

以下内容适用于写入字符串数据,但我需要double以及要写入的浮点数据。

我该怎么做?

  bool WriteOutputValue( tstring strValue)
  {

    FILE* pOutputFile = NULL;   
    // Open file
    //_tfopen_s(&pOutputFile, _T("Subtract.txt"), _T("w, ccs=UNICODE") ); 
    _tfopen_s(&pOutputFile, _T("GetBalanceTimeReport.txt"), _T("w") ); 
    if (NULL == pOutputFile)
    {
        printf("error Output filen");  
        return false;
    }   
    int nRet = _fputts( strValue.c_str(), pOutputFile);
    if (nRet < 0)
    {
        printf("error writing GetBalanceTimeReportn"); 
        fclose(pOutputFile);
        return false;
    }
    fclose(pOutputFile);
    return true;
 }

如果您想将doubles、int等输出到文件流,您要查找的函数是fprintf。http://www.cplusplus.com/reference/cstdio/fprintf/

示例:

fprintf(pOutputFile,"%d%d-f",myint1,myint2,mydouble)