How to Add spaces to variable outputs?

Hello, I would like to know how to have console space the result Variable in the output.

For example if I run the code, it shows: "Here is the result: 5Press any key to continue"

I want it should show: "Here is the result: 5 press any key to continue."

I have looked at google search but the results do not seem to be similar to my problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main()

{


	int a(3);
	int b(5);
	int result;
	
	a = a - 2;
	result = a * b; 

	cout << "Hello World! ";     // prints Hello World!
	cout << "I'm a C++ program "; // prints I'm a C++ program
	cout << " Here is the result: "; cout << " ",result;

	return 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
	int a(3);
	int b(5);

	a = a - 2;
	const int result = a * b;

	std::cout << "Hello World!\n" // prints Hello World!, and a new line
	          << "I'm a C++ program\n" // prints I'm a C++ program and a new line
	          << "Here is the result: " << result << '\n' ; // '\n' - new line
}
change line 17 to:

cout << " Here is the result: " << result << endl;
Topic archived. No new replies allowed.