VSCode-标识符“ size_t”未定义

时间:2019-09-17 05:32:23

标签: c size-t

我正在为一个简单的程序编写代码,当给定多边形的边的数量和每边的长度作为作业时,它会计算多边形的周长,问题是当我执行for (size_t i = 0; i < sidesnumber; i++)时在size_t上给我一个错误,说“标识符“ size_t”未定义“。我已经尝试过也包含库stddef.h,但它保持不变。

这是整个代码:

#include <stdio.h>

int sidesnumber = 0;
int sides[100];
int results;

main()
{
    printf("Number of Sides\n");

    sidesnumber = getchar();
    sidesnumber -= 48;

    for (size_t i = 0; i < sidesnumber; i++)
    {
        /* code */
        getchar();
        sides[i] = getchar();
        sides[i] -= 48;
    }

    for (size_t i = 0; i < sidesnumber; i++)
    {
        /* code */
        results += sides[i];
    }

    printf("The perimeter is:%d", results);
}

我正在Windows 10上使用MinGW。

我当前正在使用的所有.jsons的代码

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile C File",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${workspaceRoot}\\${fileBasename}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Run C File",
            "type": "shell",
            "command": ".\\${fileBasename}.exe"
        },
        {
            "type": "shell",
            "label": "gcc.exe build active file",
            "command": "C:/mingw64/bin/gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:/mingw64/bin"
            }
        }
    ]
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "gcc.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}\\${fileBasename}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Compile C File"
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "includePath": [
                "${workspaceFolder}",
                "C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
                "C:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "C:/mingw64/x86_64-w64-mingw32/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "C:/mingw64/bin/gcc.exe"
        },
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/mingw64/bin/gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        },
        {
            "name": "Test",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\\tr1",
                "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++",
                "C:\\mingw64\\x86_64-w64-mingw32\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\mingw64\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "compilerArgs": [],
            "browse": {
                "path": [
                    "${workspaceFolder}/**"
                ],
                "limitSymbolsToIncludedHeaders": true
            }
        }
    ],
    "version": 4
}

0 个答案:

没有答案