有123.txt文件,用记事本打开后内容是 0 20 10 30 200 30 40 50 60 20 50 30 10 0 0 0 ,等有4000多个数。如何才能循环存储到m_byte[5000]数组中去呢?////定义
BYTE* m_byte;
m_byte = new BYTE[5000];//已经将文件存储到pbuf中
CFile file("123.txt",CFile::modeRead);
DWORD dwFileLen;
dwFileLen = file.GetLength();
char *pbuf=new char[dwFileLen];
pbuf = new char[dwFileLen+1];
pbuf[dwFileLen] = 0;
file.Read(pbuf,dwFileLen);/////////////接下来改如何循环存储到m_byte[5000]中呢?
BYTE* m_byte;
m_byte = new BYTE[5000];//已经将文件存储到pbuf中
CFile file("123.txt",CFile::modeRead);
DWORD dwFileLen;
dwFileLen = file.GetLength();
char *pbuf=new char[dwFileLen];
pbuf = new char[dwFileLen+1];
pbuf[dwFileLen] = 0;
file.Read(pbuf,dwFileLen);/////////////接下来改如何循环存储到m_byte[5000]中呢?
解决方案 »
- 一段资料书上的opengl入门实例,运行时只是黑屏,没有效果,急,帮忙看看,感激不尽
- 请问为何我用SetTimeZoneInformation函数设置了时区,右下角看到时间变了,但是时间/日期属性里的时区还是显示是北京+8时区,这个怎么改?
- 关于进程问题
- DbVisualizer 6.0.12 客户端发现显示不对,谁知道是哪里配置还是本身配置有问题。
- DrawText特别提问
- 我在做ASP COM,想把分页写在COM里,如何写?谢谢,最好给我个例子
- 请教:如何实现弹出对话框的默认路径
- Serialize 问题
- 请您帮我诊断一下!
- 请问如何在CEditView中画点?
- 急,什么叫做主网格轴M,副网格轴N,平滑曲面 M,N 密度
- 送分100分:某电脑发送的数据包经过路由器后数据包中是否包含此电脑的MAC信息
{ CStdioFile csfFile;
CString strFileString = "";
TRY
{
if(csfFile.Open(strFileName,CFile::modeReadWrite|CFile::shareDenyNone))
{
CString strTemp;
while( csfFile.ReadString(strTemp) )
{
strFileString += strTemp + " ";
}
csfFile.Close();
}
}
CATCH (CMemoryException, e)
{
strFileString = "";
}
END_CATCH return strFileString;
}
再用下面函数将文件内容以空格 分隔存储到 bytes数组
BOOL CUtilityEx::String2Bytes(const char* pszStr, const char* pSeperator, unsigned char* pBuffer, unsigned long& ulBufferLen)
{
string strSrc = pszStr;
string strSep = pSeperator; if (strSrc.length() == 0)
{
return FALSE;
} ulBufferLen = 0;
size_t nEqualPos = -1;
size_t nParaStaPos = 0;
do
{
nEqualPos = strSrc.find(strSep, nParaStaPos);
if (nEqualPos == string::npos)
{
string strLast = strSrc.substr(nParaStaPos, strSrc.length() - nParaStaPos);
CUtilityEx::RemoveSpace(strLast);
if(_stscanf(strLast.c_str(), _T("%x"), &pBuffer[ulBufferLen]) == 1)
{
ulBufferLen++;
}
break;
}
string strValue = strSrc.substr(nParaStaPos, nEqualPos - nParaStaPos); nParaStaPos += strValue.length() + 1; CUtilityEx::RemoveSpace(strValue); if(_stscanf(strValue.c_str(), _T("%x"), &pBuffer[ulBufferLen]) == 1)
{
ulBufferLen++;
} } while (nEqualPos != string::npos); return (ulBufferLen > 0);
}
// 用atoi赋值给BYTEBYTE m_byte[3000];
char string[] = "1 2 34 233 45";
char seps[] = " ";
int pos = 0;
char *token;
token = strtok( string, seps );
while( token != NULL )
{
m_byte[pos] = atoi(token);
pos++;
token = strtok( NULL, seps );
}