#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int progd1=72, progd2=69, progd3=76, progd4=76, progd5=79;
char H=progd1, E=progd2, L=progd3, l=progd4, O=progd5;
cout<<"\nknown :ascii1=72\n";
cout<<" ascii2=69\n";
cout<<" ascii3=76\n";
cout<<" ascii4=76\n";
cout<<" ascii5=79\n";
cout<<"\nIf all that variable spliced together, "
<<"\nthen the program will form into ASCII, that is "<<H,E,L,l,O;
getch();
}
当我编译它时,它只打印出H字。
答案 0 :(得分:0)
您需要使用插入运算符(&lt;&lt;)来为cout提供每个变量:
cout << "\n If all that variable spliced together ..." <<H<<E<<L<<l<<O;
答案 1 :(得分:0)
因为,
没有按照您的想法行事。 a,b
表示评估a
,然后评估b
,然后使用b
的结果(例如(1+1, 2*3)
为6)。
cout<<"\nIf all that variable spliced together, "<<"\nthen the program will form into ASCII, that is "<<H,E,L,l,O;
此语句评估cout<<"\nIf all that variable spliced together, "<<"\nthen the program will form into ASCII, that is "<<H
。然后它评估E
并且不对结果做任何事情,然后它评估L
并且不对结果做任何事情,依此类推。
您已经知道如何打印多个内容 - 继续链接<<
运算符。 cout<<...<<H<<E<<L<<l<<O;
。