返回信息流#include<iostream>
using namespace std;
int main()
{
int i=5;
const int &r=i;
cout<<"之前i="<<i<<"\t"<<"r="<<r<<endl;
i=i+i;
cout<<"之后i="<<i<<"\t"<<"r="<<r<<endl;
return 0;
}
对counst引用有点疑惑,就自己编了个小程序验证一下,一样的输出语句,我就把“前”字改成了“后”字,可是为什么输出的第一行不能正确显示制表符呢?
这是一条镜像帖。来源:北邮人论坛 / cpp / #80509同步于 2014/6/30
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
入门菜鸟碰难题,学长学姐们快来看看
chenheng1989
2014/6/30镜像同步22 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
#include<iostream>
using namespace std;
int main()
{
double i=5.78;
const int &r=i;
cout<<"之前i="<<i<<"\t"<<"r="<<r<<endl;
i=i+i;
cout<<"之后i="<<i<<"\t"<<"r="<<r<<endl;
return 0;
}
可是这个又可以正常输出
贴汇编:
.file "main.cpp"
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.section .rodata
.LC0:
.string "\344\271\213\345\211\215i="
.LC1:
.string "\t"
.LC2:
.string "r="
.LC3:
.string "\344\271\213\345\220\216i="
.text
.globl main
.type main, @function
main:
.LFB957:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
pushl %esi
pushl %ebx
subl $40, %esp
movl $5, 24(%esp)
leal 24(%esp), %eax
movl %eax, 28(%esp)
movl 28(%esp), %eax
movl (%eax), %ebx
.cfi_escape 0x10,0x3,0x7,0x75,0x0,0x9,0xf0,0x1a,0x38,0x1c
.cfi_escape 0x10,0x6,0x7,0x75,0x0,0x9,0xf0,0x1a,0x34,0x1c
movl 24(%esp), %esi
movl $.LC0, 4(%esp)
movl $_ZSt4cout, (%esp)
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl %esi, 4(%esp)
movl %eax, (%esp)
call _ZNSolsEi
movl $.LC1, 4(%esp)
movl %eax, (%esp)
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl $.LC2, 4(%esp)
movl %eax, (%esp)
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl %ebx, 4(%esp)
movl %eax, (%esp)
call _ZNSolsEi
movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, 4(%esp)
movl %eax, (%esp)
call _ZNSolsEPFRSoS_E
movl 24(%esp), %edx
movl 24(%esp), %eax
leal (%edx,%eax), %eax
movl %eax, 24(%esp)
movl 28(%esp), %eax
movl (%eax), %ebx
movl 24(%esp), %esi
movl $.LC3, 4(%esp)
movl $_ZSt4cout, (%esp)
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl %esi, 4(%esp)
movl %eax, (%esp)
call _ZNSolsEi
movl $.LC1, 4(%esp)
movl %eax, (%esp)
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl $.LC2, 4(%esp)
movl %eax, (%esp)
call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
movl %ebx, 4(%esp)
movl %eax, (%esp)
call _ZNSolsEi
movl $_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, 4(%esp)
movl %eax, (%esp)
call _ZNSolsEPFRSoS_E
movl $0, %eax
addl $40, %esp
popl %ebx
.cfi_restore 3
popl %esi
.cfi_restore 6
movl %ebp, %esp
.cfi_def_cfa_register 4
popl %ebp
.cfi_restore 5
.cfi_def_cfa_offset 4
ret
.cfi_endproc
.LFE957:
.size main, .-main
.type _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB966:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $24, %esp
cmpl $1, 8(%ebp)
jne .L5
cmpl $65535, 12(%ebp)
jne .L5
movl $_ZStL8__ioinit, (%esp)
call _ZNSt8ios_base4InitC1Ev
movl $_ZNSt8ios_base4InitD1Ev, %eax
movl $__dso_handle, 8(%esp)
movl $_ZStL8__ioinit, 4(%esp)
movl %eax, (%esp)
call __cxa_atexit
.L5:
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE966:
.size _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
.type _GLOBAL__I_main, @function
_GLOBAL__I_main:
.LFB967:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $24, %esp
movl $65535, 4(%esp)
movl $1, (%esp)
call _Z41__static_initialization_and_destruction_0ii
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE967:
.size _GLOBAL__I_main, .-_GLOBAL__I_main
.section .ctors,"aw",@progbits
.align 4
.long _GLOBAL__I_main
.weakref _ZL20__gthrw_pthread_oncePiPFvvE,pthread_once
.weakref _ZL27__gthrw_pthread_getspecificj,pthread_getspecific
.weakref _ZL27__gthrw_pthread_setspecificjPKv,pthread_setspecific
.weakref _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_,pthread_create
.weakref _ZL20__gthrw_pthread_joinmPPv,pthread_join
.weakref _ZL21__gthrw_pthread_equalmm,pthread_equal
.weakref _ZL20__gthrw_pthread_selfv,pthread_self
.weakref _ZL22__gthrw_pthread_detachm,pthread_detach
.weakref _ZL22__gthrw_pthread_cancelm,pthread_cancel
.weakref _ZL19__gthrw_sched_yieldv,sched_yield
.weakref _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t,pthread_mutex_lock
.weakref _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t,pthread_mutex_trylock
.weakref _ZL31__gthrw_pthread_mutex_timedlockP15pthread_mutex_tPK8timespec,pthread_mutex_timedlock
.weakref _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t,pthread_mutex_unlock
.weakref _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t,pthread_mutex_init
.weakref _ZL29__gthrw_pthread_mutex_destroyP15pthread_mutex_t,pthread_mutex_destroy
.weakref _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t,pthread_cond_broadcast
.weakref _ZL27__gthrw_pthread_cond_signalP14pthread_cond_t,pthread_cond_signal
.weakref _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t,pthread_cond_wait
.weakref _ZL30__gthrw_pthread_cond_timedwaitP14pthread_cond_tP15pthread_mutex_tPK8timespec,pthread_cond_timedwait
.weakref _ZL28__gthrw_pthread_cond_destroyP14pthread_cond_t,pthread_cond_destroy
.weakref _ZL26__gthrw_pthread_key_createPjPFvPvE,pthread_key_create
.weakref _ZL26__gthrw_pthread_key_deletej,pthread_key_delete
.weakref _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t,pthread_mutexattr_init
.weakref _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti,pthread_mutexattr_settype
.weakref _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t,pthread_mutexattr_destroy
.ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-4)"
.section .note.GNU-stack,"",@progbits
看我写的啊,大哥,我是想验证const引用的问题才编的程,然后问题验证了,意外出了别的问题
【 在 xiaoyu2008 的大作中提到: 】
: 这跟const 引用有毛关系
菜鸟表示看不懂
【 在 FromSixToTen 的大作中提到: 】
: 贴汇编:
: .file "main.cpp"
: .local _ZStL8__ioinit
: ...................