Printing out leading zero ?

closed account (9hUqko23)
How do I get my output numbers to be 0001 instead of just 1. I don't want my program dropping the leading zero as it is very important. The variable I'm concerned with is int a, b.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  #include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main(void)
{
	ofstream myfile("Correct Alarm Name Convention.csv");
	if (myfile.is_open())
	{

		int a, b, c;
		int i, j;
		char A, B;
		//All PCB alarm nomenclatures should be the same for every PCB.
		//myfile << "%%%%%%%%%%%%%%%%%%%%%%" << endl; 
		//myfile << "Power Circuit Breakers" << endl;
		//myfile << "%%%%%%%%%%%%%%%%%%%%%%" << endl;
		//for the DSF lesel breakers found off MMS.
		for (i = 0; i < 601; i++)
		{
			cout << "Input an PCB equipment prefix" << endl;
			cin >> A;
			cout << "Input a PCB equipment number" << endl;
			cin >> a;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PHASE" << " " << "A(3)" << " " << "VOLTS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PHASE" << " " << "B(2)" << " " << "VOLTS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PHASE" << " " << "C(1)" << " " << "VOLTS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PHASE" << " " << "A(3)" << " " << "AMPS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PHASE" << " " << "B(2)" << " " << "AMPS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PHASE" << " " << "C(1)" << " " << "AMPS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "NEUTRAL AMPS" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "INST KVAR" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "INST KW" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PF" << endl;
		} 
		//for ITS level breakers found off MMS.
		for (i = 0; i < 187; i++)
		{
			cout << "Input a PCB equipment number" << endl;
			cin >> c;
			myfile << "PCB" << " " << "#" << c << " " << "PHASE" << " " << "A(3)" << " " << "VOLTS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "PHASE" << " " << "B(2)" << " " << "VOLTS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "PHASE" << " " << "C(1)" << " " << "VOLTS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "PHASE" << " " << "A(3)" << " " << "AMPS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "PHASE" << " " << "B(2)" << " " << "AMPS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "PHASE" << " " << "C(1)" << " " << "AMPS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "NEUTRAL AMPS" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "INST KVAR" << endl;
			myfile << "PCB" << " " << "#" << c << " " << "INST KW" << endl;
			myfile << "PCB" << " " << "#" << A << "-" << a << " " << "PF" << endl;
		}
		//cout << "Input Reg. Prefix" << endl;
		//cin >> B;
		//cout << "Input Reg. number" << endl;
		//cin >> b; 
		//myfile << "%%%%%%%%%%%%%%%%" << endl;
		//myfile << "   Regulators" << endl;
		//myfile << "%%%%%%%%%%%%%%%%" << endl;
		for (i = 0; i < 1417; i++)
		{
			cout << "Input a Regulator prefix" << endl;
			cin >> B;
			cout << "Input a Regulator number" << endl;
			cin >> b;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "AMPS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "KVAR" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "KW" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "OPS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "PF" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "TAP POS." << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "C(1)" << " " << "VOLTS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "AMPS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "KVAR" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "KW" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "OPS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "PF" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "TAP POS." << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "B(2)" << " " << "VOLTS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "AMPS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "KVAR" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "KW" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "OPS" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "PF" << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "TAP POS." << endl;
			myfile << "REGULATOR" << " " << "#" << B << "-" << b << " " << "PHASE" << " " << "A(3)" << " " << "VOLTS" << endl;
		}
		myfile.close();
	}
	else
	{
		cout << "Unable to open file" << endl;
	}
	
}
Look at setw and setfill.
Topic archived. No new replies allowed.