如何解决char *变量的第一个变量中有多余的十六进制数
我有这段代码:
num = sshObj->exec_ssh_command("systemctl list-units --state active | grep service | wc -l");
active = std::stoi(num);
for (int i = 0; i < active; i++)
{
std::string str = "systemctl list-units --state active | grep service | sed -s -n " ;
char* command = nullptr;
command = new char[str.size() + 1];
strcpy(command,str.c_str());
}
当我调试它时,这是command
的内容:
0x555555773b90 "systemctl list-units --state active | grep service | sed -s -n "
显然我不能使用它。为什么这样呢?我该怎么办?
解决方法
command
是char *
。调试器很可能会向您显示其指向的地址。还将char *
视为以null结尾的字符串,并显示其内容用引号引起来。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。