为什么没有显示输出 [英] why no output is displaying

查看:143
本文介绍了为什么没有显示输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么此代码不显示任何输出:而是如果我们使用

Why this code is not displaying any output: Instead if we use

cout << &s1.f 

cout << &s1.i

提供正确的输出。

# include <iostream>
using namespace std;

struct s
{
char c;
int i;
float f;

}s1;

int main()
{
cout << &s1.c;
}


推荐答案

code> operator ,它接受 char * ,并将其显示为以null结尾的字符串。如果要显示指针地址,请将指针转换为 void *

There is an overload of operator<< that takes a char* and displays it as a null-terminated string. If you want to display the pointer address, cast the pointer to void*.

这篇关于为什么没有显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆