如何在C++中显示数字变量?

Cal*_*orn -2 c++ variables cout

我有4个变量叫:number,x,y,z.

x = 1,
y = 2,
z = 3
Run Code Online (Sandbox Code Playgroud)

我希望变量号能够取x,y和z的值,并能够显示值123

到目前为止我试过这个:

number = x + y + z; but the answer is 6.
Run Code Online (Sandbox Code Playgroud)

要么

number = x << y << z; but the output is not what I want.
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

Mik*_*all 5

在C++中:

cout << x << y << z
Run Code Online (Sandbox Code Playgroud)

在C:

printf("%d%d%d", x, y, z);
Run Code Online (Sandbox Code Playgroud)

或者将它们放在一个字符串中:

ostringstream convert;   // stream used for the conversion

convert << x << y << z; 

std::string result = convert.str(); 
Run Code Online (Sandbox Code Playgroud)