为什么cout用<<而不是+产生正确的字符串输出? [英] Why does cout produce the correct string output with <<, but not with +?
本文介绍了为什么cout用<<而不是+产生正确的字符串输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这没有显示输出:
int x = 10;
cout<<"Hello C++ " + x ;
但这确实显示输出:
int x = 10;
cout<<"Hello C++ ";
cout<<x<<endl;
出什么问题了?它们看起来完全一样.
What is the problem? They seem exactly the same.
顺便说一句,我正在Visual Studio 2010上使用Visual C ++ 6.0.
BTW I'm Using Visual C++ 6.0 On Visual Studio 2010 .
推荐答案
尝试使用以下代码代替: cout<<"Hello C ++" + x;
Try using instead of: cout<<"Hello C++ " + x ;
cout<<"Hello C++ " << x ;
这篇关于为什么cout用<<而不是+产生正确的字符串输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文