input file help

i need help with getting an 8 digit integer from a text file and seting it equal to number
everything else in the program works

please help if you can


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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
 #include <iomanip>
#include <iostream>
#include <cmath>
#include<fstream>
#include<cstdlib>
#include<string>

using namespace std;

int number, n1, n2, n3, n4, n5, n6, n7, n8,a,i;

void main()
{
	string ifilename, ofilename, line;
	ifstream inFile, checkOutFile;
	ofstream outFile;
	char response;
	// Input file
	cout << "Please enter the name of the file you wish to open : ";
	cin >> ifilename;
	inFile.open(ifilename.c_str());
	if (inFile.fail())
	{
		cout << "The file " << ifilename << " was not successfully opened." << endl;
		cout << "Please check the path and name of the file. " << endl;
		exit(1);
	}
	else
	{
		cout << "The file is successfully opened." << endl;
	}
	// Output file
	cout << "Please enter the name of the file you wish to write : ";
	cin >> ofilename;
	checkOutFile.open(ofilename.c_str());
	if (!checkOutFile.fail())
	{
		cout << "A file " << ofilename << " exists.\nDo you want to continue and overwrite it? (y/n) : ";
		cin >> response;
		if (tolower(response) == 'n')
		{
			cout << "The existing file will not be overwritten. " << endl;
			exit(1);
		}
	}
	outFile.open(ofilename.c_str());
	if (outFile.fail())
	{
		cout << "The file " << ofilename << " was not successfully opened." << endl;
		cout << "Please check the path and name of the file. " << endl;
		exit(1);
	}
	else
	{
		cout << "The file is successfully opened." << endl;
	}


			a = number;  //saves imput in another integer

			n8 = number % 10;  //seperates numbers into digits
			number /= 10;
			n7 = number % 10;
			number /= 10;
			n6 = number % 10;
			number /= 10;
			n5 = number % 10;
			number /= 10;
			n4 = number % 10;
			number /= 10;
			n3 = number % 10;
			number /= 10;
			n2 = number % 10;
			number /= 10;
			n1 = number % 10;
			number /= 10;


			for (i = 9; i > 0; i--)
			{

				if (0 < n1 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n2 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n3 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n4 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n5 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n6 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n7 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";
				}
				if (0 < n8 - 8)
				{
					cout << "*";
					outFile << "*";
				}
				else
				{
					cout << " ";
					outFile << " ";

				}
				n1++; // changes value by one
				n2++;
				n3++;
				n4++;
				n5++;
				n6++;
				n7++;
				n8++;

				cout << endl;
				outFile << endl;

			};
			cout << a << endl; // displays original imput
			outFile << a << endl;

	// Close files
	inFile.close();
	outFile.close();
}
// main
does any one know how to input a file to an integer
@awitt

Here's your program, slightly modified, to read the text file. I changed the variable to a long. i did not check if the number being read was to big for an int or not, so, that may be still be okay, as an int. Anyway, here it is..
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <iomanip>
#include <iostream>
#include <cmath>
#include<fstream>
#include<cstdlib>
#include<string>

using namespace std;

int number, n1, n2, n3, n4, n5, n6, n7, n8, i;

void main()
{
	string ifilename, ofilename, line;
	ifstream inFile, checkOutFile;
	long numbers, a;
	ofstream outFile;
	char response;
	// Input file
	cout << "Please enter the name of the file you wish to open : ";
	cin >> ifilename;
	inFile.open(ifilename.c_str());
	if (inFile.fail())
	{
		cout << "The file " << ifilename << " was not successfully opened." << endl;
		cout << "Please check the path and name of the file. " << endl;
		exit(1);
	}
	else
	{
		cout << "The file is successfully opened." << endl;
	}
	// Output file
	cout << "Please enter the name of the file you wish to write : ";
	cin >> ofilename;
	checkOutFile.open(ofilename.c_str());
	if (!checkOutFile.fail())
	{
		cout << "A file " << ofilename << " exists.\nDo you want to continue and overwrite it? (y/n) : ";
		cin >> response;
		if (tolower(response) == 'n')
		{
			cout << "The existing file will not be overwritten. " << endl;
			exit(1);
		}
	}
	outFile.open(ofilename.c_str());
	if (outFile.fail())
	{
		cout << "The file " << ofilename << " was not successfully opened." << endl;
		cout << "Please check the path and name of the file. " << endl;
		exit(1);
	}
	else
	{
		cout << "The file is successfully opened." << endl;
	}

	
	inFile >> numbers;  // reads number from file
	a = numbers; //saves input in another integer
	n8 = numbers % 10;  //seperates numbers into digits
	numbers /= 10;
	n7 = numbers % 10;
	numbers /= 10;
	n6 = numbers % 10;
	numbers /= 10;
	n5 = numbers % 10;
	numbers /= 10;
	n4 = numbers % 10;
	numbers /= 10;
	n3 = numbers % 10;
	numbers /= 10;
	n2 = numbers % 10;
	numbers /= 10;
	n1 = numbers % 10;
	numbers /= 10;


	for (i = 9; i > 0; i--)
	{

		if (0 < n1 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n2 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n3 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n4 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n5 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n6 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n7 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";
		}
		if (0 < n8 - 8)
		{
			cout << "*";
			outFile << "*";
		}
		else
		{
			cout << " ";
			outFile << " ";

		}
		n1++; // changes value by one
		n2++;
		n3++;
		n4++;
		n5++;
		n6++;
		n7++;
		n8++;

		cout << endl;
		outFile << endl;

	};
	cout << a << endl; // displays original imput
	outFile << a << endl;

	// Close files
	inFile.close();
	outFile.close();
}
Topic archived. No new replies allowed.