1.以下代码:
TCHAR st[]=_T("6.001.35");
我现在要用st中的值与5.06比较
if (st>5.06) 不行
请问如何做?
2.某文件有文件版本号:5.50.4134.600,产品版本号:1.0.3705.12
现已将文件信息读入到vsf变量中,但是其中的vsf.dwFileVersionLS和vsf.dwProductVersionLS的值一样这是怎么回事?另外如何取得产品版本号中的3705??

解决方案 »

  1.   

    CString就是基于TCHAR的!!可以直接用atof转换成double,或float,再比较就行了!
    int main()
    {
    TCHAR st[]=_T("6.001.35");
    double dvalue = atof(str1);
    if ( dvalue >5.6)
    cout<<"True!"<<endl;
    }
      

  2.   

    Example/* ATOF.C: This program shows how numbers stored
     * as strings can be converted to numeric values
     * using the atof, atoi, and atol functions.
     */#include <stdlib.h>
    #include <stdio.h>void main( void )
    {
       char *s; double x; int i; long l;   s = "  -2309.12E-15";    /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "7.8912654773d210";  /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "  -9885 pigs";      /* Test of atoi */
       i = atoi( s );
       printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );   s = "98854 dollars";     /* Test of atol */
       l = atol( s );
       printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
    }
    Outputatof test: ASCII string:   -2309.12E-15   float:  -2.309120e-012
    atof test: ASCII string: 7.8912654773d210   float:  7.891265e+210
    atoi test: ASCII string:   -9885 pigs      integer: -9885
    atol test: ASCII string: 98854 dollars      long: 98854
      

  3.   

    1、将数字转换为字符串再进行比较:
    TCHAR st[]=_T("6.001.35");
    float fVer = 5.06;
    CString strVer;
    strVer.Format( %f", fVer );
    if( strcmp( st, strVer ) > 0 )
    ...2、取版本的完整方法:
    #include <winver.h>
    #pragma comment ( lib, "version.lib" )void GetVer( int &iVerMajor, int &iVerMinor, int &iVerBuildTimes )
    {
    char szFile[MAX_PATH];
    GetModuleFileName( NULL, szFile, sizeof(szFile) );VS_FIXEDFILEINFO *lpInfo;
    DWORD  dw;
    DWORD  dwSize = GetFileVersionInfoSize( szFile, &dw );LPVOID lpData = (LPVOID)new char[dwSize];
    GetFileVersionInfo( szFile, 0, dwSize, lpData );UINT ui;
    VerQueryValue( lpData, "\\", (LPVOID*)&lpInfo, &ui );iVerMajor = HIWORD( lpInfo->dwFileVersionMS );
    iVerMinor = LOWORD( lpInfo->dwFileVersionMS );
    iVerBuildTimes = LOWORD( lpInfo->dwFileVersionLS );delete [] lpData; 
    }
      

  4.   

    1.感谢各位的参与。
    2.我要的是精确比较。
    3.关于取文件产品版本号,我的代码:
            HRESULT hr;
            VS_FIXEDFILEINFO vsf;        hr = GetFileVersion (szFileName, &vsf);        if (FAILED(hr))
            {
                throw hr;
            }
            //我的文件版本号为5.50.4134.600
            //产品版本号为1.0.3705.12
    DWORD dwFileVersionLS = vsf.dwFileVersionLS >> 16;
            //这样dwFileVersionLS中的值为4134
            //我想得到产品版本号中的3705如何得到?
            //用vsf.dwProductVersionLS不行,因为它的值跟dwFileVersionLS一样,怎么解决?//GetFileVersion函数HRESULT GetFileVersion (LPTSTR filename, VS_FIXEDFILEINFO *pvsf) 
    {
        DWORD dwHandle;
        HRESULT hrReturn = S_OK;
        char* pver = NULL;    try 
        {
            DWORD cchver = GetFileVersionInfoSize(filename,&dwHandle);
            if (cchver == 0)
            {
                throw LastError();
            }
            pver = new char[cchver];        if (!pver)
            {
                throw E_OUTOFMEMORY;
            }        BOOL bret = GetFileVersionInfo(filename,dwHandle,cchver,pver);
            if (!bret) 
            {
                throw LastError();
            }
            UINT uLen;
            void *pbuf;
            bret = VerQueryValue(pver,_T("\\"),&pbuf,&uLen);
            if (!bret) 
            {
                throw LastError();
            }
            memcpy(pvsf,pbuf,sizeof(VS_FIXEDFILEINFO));
        }
        catch (HRESULT hr)
        {
            hrReturn = hr;
        }    delete[] pver;
        return hrReturn;
    }HRESULT LastError () 
    {
       HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
       if (SUCCEEDED(hr))
       {
          hr = E_FAIL;
       }
       return hr;
    }
      

  5.   

    哎!
    来晚了!
    这里也有很简单的问题可得分的:
    http://expert.csdn.net/Expert/TopicView1.asp?id=1189886
      

  6.   

    1.atof, atoi, _atoi64, atol
    Convert strings to double (atof), integer (atoi, _atoi64), or long (atol).double atof( const char *string );int atoi( const char *string );__int64 _atoi64( const char *string );long atol( const char *string );2.GetFileVersionInfo
    This function returns version information about a specified file. BOOL GetFileVersionInfo(
    LPTSTR lptstrFilename,
    DWORD dwHandle,
    DWORD dwLen,
    LPVOID lpData);