C++ MinGW x64 Debugging - value of std::string doesn't display properly

260 views Asked by At

I'm using CLion 1.0.3 with MinGW 64 to create my projects, and when I debug, my std::string variable displays (in the variables/watches panel) fine while in the scope of the main function, but as soon as I pass the variable to my class constructor, the value copied to the parameter displays really strangely. The value remains unchanged - I checked by attempting to cout the string, which outputs the same as the original - but the display in the variables panel appears to be a set of characters, most of which are represented by an escape sequence, that does not correspond to the string object at all.

In fact, the display appears to be reading the bytes that make up the string object (though I could be wrong), rather than the string that the object represents. It's better explained with an example:

int main()

int main() {
    string string1 = "test.txt"; //Debugger displays 'string1 = {std::string} "test.txt"' - normal.
    cout << string1 << endl; //Console displays 'text.txt' - normal.
    File f(string1); // <--- Passing to this constructor
    return 0;
}

File::File(std::string) - (Note that the first File is a namespace, the second is the class, and the third is the constructor)

Brad::API::File::File::File(std::string passed) {
    std::cout << passed << std::endl; // Outputs "test.txt" - normal
}

All is great as far as program function goes, except that when I tried to view the value of passed, it shows up as passed = {std::string} "<\022;\000�yA\000��(\000\001\000\000\000\200�(\000�\023@\000�\016;\000/\000\000 ...(I removed ~54,000 more characters from here for the sake of readability)"...<error: Cannot access memory at address 0x294000>

As mentioned, there was roughly 54,000 characters to show for an 8-character string, which makes me think that it might just be reading the memory and giving me the raw bytes.

I'm utterly confused as to why this might be happening, and any help would be greatly appreciated.

0

There are 0 answers