1)你的 std::string 不是一个普通的 ascii 字符串它是一个结构(实际上是一个类)所以你不能获取地址并找到字符串
在您的特定情况下,由于您的字符串 test 的长度小于阈值,您很幸运,您可以在屏幕截图中看到它,将74 65 73 74 设为 ascii,您会注意到它是“test”
并且您的 int 看起来是可见的 尝试查看 0xa == 0n10
编辑
您的源代码略有修改以显示上述语句的结果
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
//small string will be embedded inside std::string class
// you can see 74657374 (hex for "test")
string s1{ "test" };
cout << s1 << endl;
cout << &s1 << endl;
printf("%llx\n", *(__int64 *)(&s1) );
printf("%p\n" , s1.c_str());
printf("%s\n" , s1.c_str());
cout << "\n=========================================================================\n" ;
// big string a pointer will be present to the c_str member
// you cannot see the string unless you dereference the pointer for c_str() member
string s2 { "this is a very very very very very very biggy biggy biggy stringyyyyyy" };
cout << s2 << endl;
cout << &s2 << endl;
printf("%llx\n", *(__int64 *)&s2 );
printf("%p\n" , s2.c_str());
printf("%s\n" , s2.c_str());
return getchar();
}
结果
>ogrish.exe
test
001AF7C8
eafc0074736574 <<<< see the hex embedded
001AF7C8 << both &std::string and std::strin.c_str() are same
test << c_str()
=========================================================================
this is a very very very very very very biggy biggy biggy stringyyyyyy
001AF7E0 &std::string
1af7f000265cf0 << address of std::string and c_str() are different
00265CF0 & string->c_str()
this is a very very very very very very biggy biggy biggy stringyyyyyy << c_str()
顺便说一句,请记住,如果您附加到此控制台进程,则所有代码都已经运行,并且堆栈中的所有内容都可能超出范围并包含您需要单步执行以检查调试器上的内容未执行和附加的虚假值