cout in the same line

I cant get the output as below. the output keep display from up to down order. how to put it on the right side. such as for name and personnel id?

The output should be as below:

Name:	james				Personnel ID : 1104		
Month: October 2012				KWSP number: 10312478
Position: Maid
------------------------------------------------------------------------------------------------

Salary			: $ 445.67
KWSP deduction	: $ 40.11
Net Salary		: $ 405.56

************************************************************
Name:	Izrel					Personnel ID : 0509			
Month: October 2012				KWSP number: 12345678
Position: Gardener
------------------------------------------------------------------------------------------------

Salary			: $ 395.90
KWSP deduction	: $ 35.63
Net Salary		: $ 360.27

Last edited on
The obvious answer would be to output Personnel ID the same time your output the name. ex:
1
2
std::cout << "Name: " << std::setfill( ' ' ) << std::setw( 5 ) << name_variable << setw( 15 ) << "Personnel ID :  " << ID_variable << std::endl;
//output the rest 


Or depending on your OS you can move the cursor in the console/terminal and then output there.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//windows
#include <windows.h>
#include <iostream>

void gotoXY( const short &x , const short &y )
{
    HANDLE ohandle = GetStdHandle( STD_OUTPUT_HANDLE );
    COORD pos{ x , y };
    SetConsoleCursorPosition( ohandle , pos );
}

int main()
{
    std::cout << "Name: Giblit" << std::endl;
    gotoXY( 25 , 0 );
    std::cout << "ID: 1234" << std::endl;
}
Topic archived. No new replies allowed.