c++ - 下标需要数组或指针 ERROR

标签 c++

我知道我的错误是什么,但不知道如何解决。

我正在编写一个 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/

相关文章:

C++ "Virtual functions handling on multiple base classes"

c++ - 条件运算符(<、>)在 gsl 插值函数中不起作用

c++ - 在 `using Base::operator T` 是模板类型参数的情况下,是否允许 `T`?

c++ - 数组引用速度与按位运算符

c++ - 使用 MySQL C API 和 C++ 获取 MySQL 数据库表中的行

c++ - 将 sdl2 和 sdl1.2 保留在同一操作系统上?

c++ - 无法在 C++ 中打开文件

c++ - Qt C++ 用按钮增加整数来标记

c++ - Direct3D11:在设备之间共享纹理:黑色纹理

c++ - 使用 boost_foreach 遍历 unordered_map