C++ file.seekg() or file.peek() do not return any value in VS Code debug mode

0

I can't have any printed values in the watch and variables windows as I try to run the code in debug mode. I only get the message -var-create: unable to create variable object in the watch window for the seekg and peek functions.

I have installed the C++, Intellisense C++, code runner and native debug extensions in VS Code.

I typed file.peek() in the watch window under debug mode and I only get this message while stepping through my code: file.peek(): Couldn't find method std::ifstream::peek.

I also get the error Unable to step out. Operation failed with error code 0x80004004 while trying to step out (SHIFT+F11) in my code which is probably due to gdb according to this post: #215

OS : Ubuntu 16.04.2 LTS
VSCode : Version 1.14.2
gdb : GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1

Here is a sample code I am trying to debug in vscode.

debugFct.cpp:

#include <iostream>
#include <fstream>

using namespace std;

int main(){
    string fileName = "matrix.txt"; 
    ifstream file(fileName);
    file.seekg(0, ios::beg);

    int numberOfCharacters = 0;
    char numb; 
    do {
        ++numberOfCharacters;
        if (file.peek() == '\n')
            break;
    }
    while(file.get(numb));
    cout << "Number Of Characters:" << numberOfCharacters << endl;
return 0;
}

Here are my .json files:

task.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "debugFct",
            "command": "g++",
            "type": "shell",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "args": ["-std=c++11","${workspaceRoot}/debugFct.cpp"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

c_cpp_properties.json
{
    "name": "Linux",
    "includePath": [
        "/usr/include/c++/5.4.1",
        "/usr/include/linux/",
        "/usr/include/x86_64-linux-gnu/c++/5.4.1",
        "/usr/local/include",
        "/usr/include/x86_64-linux-gnu",
        "/usr/share/bash-completion/completions/g++",
        "/usr/include/x86_64-linux-gnu/c++/5/bits",
        "/usr/include/x86_64-linux-gnu/c++/5.4.1/bits",
        "${workspaceRoot}"
    ],
    "defines": [],
    "intelliSenseMode": "clang-x64",
    "browse": {
    "path": [
        "~/Documents/ptrTest/",
        "/usr/include/c++/5.4.1",
        "/usr/include/x86_64-linux-gnu/c++/5.4.1",
        "/usr/local/include",
        "/usr/include",
        "/usr/include/x86_64-linux-gnu",
        "/usr/include/x86_64-linux-gnu/c++/5.4.1/bits",
        "${workspaceRoot}"
    ],
    "limitSymbolsToIncludedHeaders": true,
    "databaseFilename": ""
    }
},


launch.json
{
"version": "0.2.0",
"configurations": [
    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceRoot}/debugFct",
        "args": ["-D_GLIBCXX_DEBUG"],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": false
            }
        ]
    }
]
}

settings.json 
{
"files.associations": {
    "string": "cpp",
    "iostream": "cpp",
    "istream": "cpp",
    "iosfwd": "cpp"
},
"C_Cpp.intelliSenseEngine": "Tag Parser",
"code-runner.executorMap":{
    "cpp": "cd $dir && g++ -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
"editor.minimap.enabled": false,
"vsicons.presets.tsOfficial": true,
"workbench.iconTheme": "vscode-icons"
}
c++
visual-studio-code
asked on Stack Overflow Aug 30, 2017 by jen mueller • edited Aug 23, 2018 by Gama11

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0