Bor*_*nth 3 c++ cout char ostream
int *i = new int(1);
cout << i << endl;
Run Code Online (Sandbox Code Playgroud)
将打印整数的地址.
char *c="cstring";
cout << c << endl;
cout << &(*c) << endl;
Run Code Online (Sandbox Code Playgroud)
两者都会打印"cstring".我想这个行为可以简单地通过ostream& operator<< (ostream& out, const char* s );IOstream库中的实现来解释.
但是,如果你真的想要打印数据c的地址怎么办呢?
cout << reinterpret_cast<void*>(c) << endl;
Run Code Online (Sandbox Code Playgroud)
要不就
cout << (void*)c << endl;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2454 次 |
| 最近记录: |