9

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?

nightfire
  • 815
  • 2
  • 12
  • 22
  • 2
    "setting" a string is a complex operation not necessarily supported by gdb. – bmargulies Nov 23 '09 at 00:20
  • ok... so you can set int variables using gdb, but not strings? I'm confused because setting strings doesn't seem much more complex than setting ints, and i know that this works: int main() { int b = 9; } (gdb) set var b = 8 // doesn't complain "setting" is the correct term for what i'm trying to do, right? – nightfire Nov 23 '09 at 00:38
  • 2
    "setting strings doesn't seem much more complex than setting ints" - well, it is. – John Zwinck Nov 23 '09 at 00:39

1 Answers1

19

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
  • 239,568
  • 38
  • 324
  • 436