C++文件未找到与编译相关的错误[关闭]

问题描述 投票:0回答:0

我正在调整我的一些 VSCode 配置以运行 c++,我遇到了这个问题。

因此,当在没有调试的情况下调用 VSCode 中的正常运行函数时,我的代码运行完美并找到了文件,但是,当使用以下配置进行调试时,我在我的程序中使用的 csv 文件上不断出现找不到文件的错误。

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "preLaunchTask": "build active file",
      "name": "CodeLLDB",
      "type": "lldb",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": []
    },
    {
      "preLaunchTask": "build active file",
      "name": "(lldb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb"
    },
    {
      "name": "GDB",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "cwd": "${workspaceFolder}",

      "MIMode": "gdb"
    }
  ]
}

任务.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build active file",
      "type": "shell",
      "command": "g++ ${file} -g -o  ${fileDirname}/${fileBasenameNoExtension}",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared"
      },
      "windows": {
        "command": "g++",
        "args": [
          "-ggdb",
          "\"${file}\"",
          "-o",
          "\"${fileDirname}\\${fileBasenameNoExtension}\""
        ]
      }
    }
  ]
}

我已经确定我存储文件的位置没有问题,或者我的代码如何发现文件。

编辑:下面列出的文件结构

│   .gitignore
│   README.md
│
├───.vscode
│       launch.json
│       tasks.json
│
├───assets
│       AboveDemoRegular-lJMd.ttf
│       github.svg
│       paperclip.svg
│
├───code
│       Boston.csv
│       dataexploration.cpp
│       dataexploration.exe
│       NaiveBayes.c++
│       NaiveBayes.exe
│       Regression.Rmd
│       titanic_project.csv
│
└───pdfs
        DataExploration.md
        DataExploration.pdf
        OverviewOfML.md
        OverviewOfML.pdf
        Regression.pdf

我正在处理的文件是 NaiveBayes.c++,如果你查看代码目录,你可以找到代码和可执行文件。

我正在尝试读取的 csv 文件是:titanic_project.csv.

就是这样,这是代码:

std::ifstream file;

    file.open(filename);

    if (!file.is_open())
    {
        printf("File not found Error.\n");
    }
    else
    {
        std::string line;
        std::getline(file, line, '\n');

        int colNum = std::count(line.begin(), line.end(), ',') + 1;

        for (int i = 1; i < colNum; i++)
        {
            std::vector<double> v;
            while (std::getline(file, line))
            {
                int pos = line.find(",");
                std::string value = line.substr(0, pos + i);
                std::string regexOut = std::regex_replace(value, std::regex("[^0-9.]"), "");
                v.push_back(std::stod(regexOut));
            }
            printVector(v);
            break;
            m.push_back(v);
        }
    }
    std::printf("Matrix Column Size: %d \n", m.size());
    file.close();

任何解决方案/建议将不胜感激。

c++ visual-studio-code debugging g++
© www.soinside.com 2019 - 2024. All rights reserved.