在gdb中设置字符串
c++:
int main()
{
string a = "a";
... ...
}
当我在 gdb 中调试时:
(gdb) set var a = "ok"
无效演员表
我运行程序并在字符串 a 初始化后在断点处暂停。我正在尝试设置它的值,但它抱怨无效的转换。正确的语法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:
这样,gdb 立即知道它需要调用一个函数(而不是您使用
operator=
尝试的函数),它知道要调用哪个函数(std:: string::assign
),并且它根本不需要转换类型(因为存在完全匹配的assign
重载)。You can do this:
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 ofassign
which matches exactly).