分割字符串的AfxExtractSubString函数

函数原型:

BOOL AfxExtractSubString(CString& rString, LPCTSTR lpszFullString, int iSubString, TCHAR chSep = ‘\n’)

参数说明:

rString  保存输出的子字符串

lpszFullString  待分割的字符串

iSubString  提取的子字符串的序号,从0开始。假如你想提取第3段,该参数就输入2

chSep  用于分割的字符,默认的是’\n’

返回值:分割成功,就返回TRUE;iSubString越界,则返回FALSE

举例说明:

CString szGet;	
CString szText = "var hq_str_sh600736=\"苏州高新,5.33,5.32,5.70,5.85,5.32,5.71,5.72,56939555,323766177,92561,5.71,121300,5.70,57200,5.69,34600,5.68,18600,5.67,130327,5.72,177801,5.73,40999,5.74,194908,5.75,69600,5.76,2011-08-12,15:03:07\";";

AfxExtractSubString(szGet, szText, 1, ',');	//取回 5.33
AfxExtractSubString(szGet, szText, 2, ',');	//取回 5.32
AfxExtractSubString(szGet, szText, 3, ',');	//取回 5.70
//想要取回苏州高新
AfxExtractSubString(szGet, szText, 0, ',');	//先取回var hq_str_sh600736="苏州高新
AfxExtractSubString(szGet, szGet, 1, '\"');	//取回 苏州高新

注意:用于分割的只能是字符,不能是字符串。

多个字符使用_tcstok函数,另外可以使用find函数自己写.

本文出自:http://www.blogjava.net/CrackRen/archive/2011/08/13/361964.html

VC修改文件时间属性(修改/访问时间)

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#include <Windows.h>
#include <time.h>
 
 
#include <sys/types.h>
#include <sys/utime.h>
 
int DateWeek(int year, int month, int day)
{
    if (month==1||month==2)
    {
        year -=1;
        month +=12;
    }
    return (day+1+2*month+3*(month+1)/5+year+(year/4)-year/100+year/400)%7;
}
int sum_day(int year,int month,int day)
{
    int days = day;
    int day_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int i;
    for(i=1;i<month;i++)days += day_month[i];
 
    int leap=0;
    if((year%4==0&&year%100==0)||(year%400==0))leap=1;
    if(leap && month>=3)days=days+1;
 
    return days;
}
 
int _tmain(int argc, _TCHAR* argv[])
{
    SYSTEMTIME st;
    FILETIME ft;
    st.wYear = 2007;
    st.wMonth = 8;
    st.wDay = 25;
    st.wHour = 15;
    st.wDayOfWeek = 5;
    st.wMinute =1;
    st.wSecond = 1;
    st.wMilliseconds = 1;
#if 0
    _utimbuf mvTime;
    time_t rawtime;
    struct tm *timeinfo;
    timeinfo = localtime(&rawtime);		
 
    timeinfo->tm_hour = st.wHour;
    timeinfo->tm_isdst = 0;
    timeinfo->tm_mday = st.wDay;
    timeinfo->tm_min = st.wMinute;
    timeinfo->tm_mon = st.wMonth;
    timeinfo->tm_sec = st.wSecond;	
    timeinfo->tm_wday = DateWeek(st.wYear,st.wMonth,st.wDay);
    timeinfo->tm_yday = sum_day(st.wYear,st.wMonth,st.wDay);
    timeinfo->tm_year = st.wYear - 1900;
 
    mvTime.actime = mktime(timeinfo);
    mvTime.modtime = mktime(timeinfo);
    _wutime(TEXT("F:/type.txt"),&mvTime);
#else
    HANDLE hFile = CreateFile(TEXT("F:/type.txt"), 
        GENERIC_READ|GENERIC_WRITE,
        FILE_SHARE_READ|FILE_SHARE_DELETE, 
        NULL, OPEN_EXISTING, 
        FILE_FLAG_BACKUP_SEMANTICS, NULL); 	
    if(hFile!=INVALID_HANDLE_VALUE)
    {
        SystemTimeToFileTime(&st,&ft);
        int res=SetFileTime(hFile,&ft,&ft,&ft);
        CloseHandle(hFile);
    }
#endif
}

,SystemTimeToFileTime接口计算出错。不知道具体原因。然后Google找到另外一种解决办法就是用utime来修改(修改/访问)时间使用_wutime修改的代码

本文出自:https://blog.csdn.net/evea804/article/details/32139941

Fixed a BUG of VC++ 6.0

MSDN documentation states that for files larger than 4 gigabytes,there is the CFileFind::GetLength64() function that returns the size as 64Bit number.But the function just return a wrong 32Bit number. Damn Microsoft!

Solution: write a derived class(CMyFtpFileFind) from CFtpFileFind,and implementing the GetLength64() member function correctly. Replace this derived class with CFtpFileFind.

Reference: http://www.codeproject.com/KB/bugs/getlength64bug.asp.aspx?print=true
Last version: https://gist.github.com/978421

Source code as following text:

class CMyFtpFileFind : public CFtpFileFind
{
public :
CMyFtpFileFind ( CFtpConnection * pConnection , DWORD dwContext = 1 ) : CFtpFileFind ( pConnection , dwContext )
{
}

virtual ~ CMyFtpFileFind () { }

__int64 GetLength64 () const
{
ASSERT ( m_hContext != NULL );
ASSERT_VALID ( this );
unsigned __int64 uRet = 0 ;

if ( m_pFoundInfo != NULL )
{
unsigned __int64 uFileSizeLow = (( LPWIN32_FIND_DATA ) m_pFoundInfo ) -> nFileSizeLow ;
unsigned __int64 uFileSizeHigh = (( LPWIN32_FIND_DATA ) m_pFoundInfo ) -> nFileSizeHigh ;
uRet = uFileSizeLow + ( uFileSizeHigh << 32 );
}

return uRet ;
}

}; // CMyFtpFileFind

 

本文出自:https://blog.csdn.net/iteye_11067/article/details/82066315

用cfile类读取大文件

/********** cfile64.h  *********/

 

class CFile64 : public CFile
{
public:

// Attributes
ULONGLONG GetPosition();


// Overridables

virtual ULONGLONG Seek(LONGLONG lOff, UINT nFrom);
virtual void SetLength(ULONGLONG dwNewLen);
ULONGLONG GetLength() ;

virtual void LockRange(ULONGLONG dwPos, ULONGLONG dwCount);
virtual void UnlockRange(ULONGLONG dwPos, ULONGLONG dwCount);


};

 

 

/*************** cfile64.cpp ***************/
#include "stdafx.h"
#include "file64.h"


// CFile64 implementation


ULONGLONG CFile64::Seek(LONGLONG lOff, UINT nFrom)
{
ASSERT_VALID(this);
ASSERT((HANDLE)m_hFile != INVALID_HANDLE_VALUE);
ASSERT(nFrom == begin || nFrom == end || nFrom == current);
ASSERT(begin == FILE_BEGIN && end == FILE_END && current == FILE_CURRENT);

   LARGE_INTEGER liOff;

   liOff.QuadPart = lOff;
liOff.LowPart = ::SetFilePointer((HANDLE)m_hFile, liOff.LowPart, &liOff.HighPart,
   (DWORD)nFrom);
if (liOff.LowPart  == (DWORD)-1)
   if (::GetLastError() != NO_ERROR)
     CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);

return liOff.QuadPart;
}

ULONGLONG CFile64::GetPosition() 
{
ASSERT_VALID(this);
ASSERT((HANDLE)m_hFile != INVALID_HANDLE_VALUE);

   LARGE_INTEGER liPos;
   liPos.QuadPart = 0;
liPos.LowPart = ::SetFilePointer((HANDLE)m_hFile, liPos.LowPart, &liPos.HighPart , FILE_CURRENT);
if (liPos.LowPart == (DWORD)-1)
   if (::GetLastError() != NO_ERROR)
     CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);

return liPos.QuadPart;
}

void CFile64::LockRange(ULONGLONG dwPos, ULONGLONG dwCount)
{
ASSERT_VALID(this);
ASSERT((HANDLE)m_hFile != INVALID_HANDLE_VALUE);

   ULARGE_INTEGER liPos;
   ULARGE_INTEGER liCount;

   liPos.QuadPart = dwPos;
   liCount.QuadPart = dwCount;
if (!::LockFile((HANDLE)m_hFile, liPos.LowPart, liPos.HighPart, liCount.LowPart, 
   liCount.HighPart))
   {
  CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);
   }
}

void CFile64::UnlockRange(ULONGLONG dwPos, ULONGLONG dwCount)
{
ASSERT_VALID(this);
ASSERT((HANDLE)m_hFile != INVALID_HANDLE_VALUE);

   ULARGE_INTEGER liPos;
   ULARGE_INTEGER liCount;

   liPos.QuadPart = dwPos;
   liCount.QuadPart = dwCount;
if (!::UnlockFile((HANDLE)m_hFile, liPos.LowPart, liPos.HighPart, liCount.LowPart,
   liCount.HighPart))
   {
  CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);
   }
}

void CFile64::SetLength(ULONGLONG dwNewLen)
{
ASSERT_VALID(this);
ASSERT((HANDLE)m_hFile != INVALID_HANDLE_VALUE);

Seek(dwNewLen, (UINT)begin);

if (!::SetEndOfFile((HANDLE)m_hFile))
  CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);
}

ULONGLONG CFile64::GetLength() 
{
ASSERT_VALID(this);

   ULARGE_INTEGER liSize;
   liSize.LowPart = ::GetFileSize((HANDLE)m_hFile, &liSize.HighPart);
   if (liSize.LowPart == (DWORD)-1)
   if (::GetLastError() != NO_ERROR)
   CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);

return liSize.QuadPart;
}


/

LONGLONG是64位整型,这样在理论上可支持的最大文件为18000000000GB,你也可以根据自己的需要重载CFile的其他函数

本文出自:https://blog.csdn.net/jrt88/article/details/4392838/