在gdb中设置字符串

发布于 2024-08-12 02:33:06 字数 253 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九命猫 2024-08-19 02:33:06

您可以这样做:

call a.assign("ok")

这样,gdb 立即知道它需要调用一个函数(而不是您使用 operator= 尝试的函数),它知道要调用哪个函数(std:: string::assign),并且它根本不需要转换类型(因为存在完全匹配的 assign 重载)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文