【发布时间】:2013-01-15 14:55:13
【问题描述】:
我是一个 c++ 新手,只是尝试编写一些代码来自己进行实验。
最近遇到一个无法调试的问题。
char acExpReason[128];
char acReason[] = "An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern operating systems.";
memcpy(acExpReason, acReason, sizeof(acExpReason));
std::string strExpReason(acExpReason);
我使用VS2005在每一行添加断点进行调试。
当它到达第二行的断点时,Autos中的变量名和值信息是:
acriason 0x00f6f78c“ììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììì”char [147]
acexpreseash 0x00f6f828“ììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììì캔char [128]
当它到达第三行的断点时,Autos中的变量名和值信息是:
acexpreseash 0x00f6f828“ììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììì캔char [128]
acReason 0x00f6f78c “错误消息是发生意外情况时显示的信息,通常在计算机或其他设备上。在现代操作系统上。”字符 [147]
当它到达第四行的断点时,Autos中的变量名和值信息是:
acExpReason 0x00f6f828“错误消息是在发生意外情况时显示的信息,通常在计算机或其他设备上。在现代 ÌÌÌÌÌÌÌ̺”字符 [128]
acReason 0x00f6f78c “错误消息是发生意外情况时显示的信息,通常在计算机或其他设备上。在现代操作系统上。”字符 [147]
strExpReason 错误指针
执行完最后一行后,Autos中的信息为:
acExpReason 0x00f6f828“错误消息是在发生意外情况时显示的信息,通常在计算机或其他设备上。在现代 ÌÌÌÌÌÌÌ̺”字符 [128]
acReason 0x00f6f78c “错误消息是发生意外情况时显示的信息,通常在计算机或其他设备上。在现代操作系统上。”字符 [147]
strExpReason "错误消息是出现意外情况时显示的信息,通常在计算机或其他设备上。在现代 ÌÌÌÌÌÌÌ̺"
基本上我的代码想要做的只是有一个完整的 msg 行存储在 acReason[] 中,并且还有一个固定长度的完整 msg 的副本(这里是 128)。
但我不知道为什么 acExpReason 和 strExpReason(acExpReason 的字符串版本)会以一些我不想要的奇怪字符“ÌÌÌÌÌÌÌ̺”结尾(因为稍后我将使用此字符串与其他字符串进行比较) .
我尝试使用 memcpy、strcpy 和 strncpy,但它们最终都在字符串末尾添加了那组奇怪的字符。
有人可以帮忙吗? 非常感谢。
【问题讨论】:
标签: c++ visual-studio char memcpy