views:

267

answers:

1

c++:

int main() 
    { 
    string a = "a"; 
    ... ... 
    }

when i debug in gdb:

(gdb) set var a = "ok"
Invalid cast

I run the program and pause at a break point after string a has been initialized. I'm trying to set its value, but it complains about invalid cast. What's the proper syntax for this?

+7  A: 

You can do this:

call a.assign("ok")

This way, gdb knows right away that it needs to call a function (rather than what you tried using operator=), it knows what function to call (std::string::assign), and it doesn't need to convert types at all (since there's an overload of assign which matches exactly).

John Zwinck