gpt4 book ai didi

eclipse - 字符串的值没有出现在eclipse mars CDT中

转载 作者:太空宇宙 更新时间:2023-11-04 12:58:47 25 4
gpt4 key购买 nike

为什么Eclipse Mars CDT中strings的值没有出现在表达式或variables窗口中?它显示为 {...},但我想在值选项卡下查看值本身。

我该怎么做?

最佳答案

这里发生的事情是 CDT 显示 GDB 提供给它的信息。

对于一个简单的程序,调试器在返回 0 的行上停止;

#include <string>
using namespace std;

int main() {
string mystring = "my string here";
return 0;
}

这是我在 CDT 变量 View 中看到的:

cdt view of variable

这与我在 GDB 中看到的相符:

(gdb) p mystring 
$1 = {static npos = <optimised out>,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
_M_p = 0x602028 "my string here"}}

pretty-print C++

但是,我怀疑您想要的是 libstdc++ 的 pretty-print ,它使变量 View 看起来像这样:

string pretty printed

创建一个包含以下内容的 ~/.gdbinit 文件(更新您机器的路径)

python
import sys
sys.path.insert(0, '/usr/share/gcc-4.8/python/')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

然后将您的启动配置指向该 gdbinit 文件并开始调试。

关于eclipse - 字符串的值没有出现在eclipse mars CDT中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34837211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com