我知道我的错误是什么,但不知道如何解决。
我正在编写一个 winAPI 来计算找到多少个“a”字符是一个 givien 文件。 我仍然收到错误“下标需要数组或指针”(请在代码中找到注释)
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
WCHAR str=L'a';
HANDLE A;
TCHAR *fn;
fn=L"d:\\test.txt";
A= CreateFile(fn,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(A==INVALID_HANDLE_VALUE)
{
_tprintf(L"cannot open file \n");
}
else
{
DWORD really;
int countletter;
int stringsize;
do
{
BYTE x[1024];
ReadFile(A,x,1024,&really,NULL);
stringsize = sizeof(really);
for(int i =0;i<stringsize;i++)
{
if(really[i]==str) //here Im getting the error
countletter++;
}
}while(really==1024);
CloseHandle(A);
_tprintf(L"NUmbers of A's found is %d \n",countletter);
}
return 0;
}
现在我知道我无法在数组和 WCHAR 之间进行比较,但是如何修复它?
最佳答案
您的变量 really
既不是数组也不是指针,因此对其下标 (really[i]
) 是非法的。
关于c++ - 下标需要数组或指针 ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2953086/