This repository was archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalFileChangerForOutputTable.cpp
More file actions
123 lines (100 loc) · 2.84 KB
/
finalFileChangerForOutputTable.cpp
File metadata and controls
123 lines (100 loc) · 2.84 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include "header.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
void appendLine(std::ofstream& outputFile, const std::string& line,const std::string& line2) {
std::string concat = line + "~" + line2 + "~";
outputFile << concat << std::endl;
}
int finalFileChangerForOutputTable()
{
std::ifstream file1("d1.txt");
std::ifstream file2("d2.txt");
std::ofstream outputFile("d5.txt");
if (!file1.is_open()) {
std::cout << "Unable to open d1.txt" << std::endl;
return 1;
}
if (!file2.is_open()) {
std::cout << "Unable to open d2.txt" << std::endl;
return 1;
}
if (!outputFile.is_open()) {
std::cout << "Unable to open d5.txt" << std::endl;
return 1;
}
std::string line1, line2;
while (true) {
string one,two;
if (std::getline(file1, line1)) {
// Read a line from file4
if (std::getline(file2, line2)) {
// Append the lines to outputFile2
appendLine(outputFile, line1, line2);
} else {
// Reached the end of file4, exit the loop
break;
}
} else {
// Reached the end of file3, exit the loop
break;
}
}
while (std::getline(file1, line1)) {
appendLine(outputFile, line1," ");
}
while (std::getline(file2, line2)) {
appendLine(outputFile, line2," ");
}
file1.close();
file2.close();
outputFile.close();
std::ifstream file3("d3.txt");
std::ifstream file4("d4.txt");
std::ofstream outputFile2("d6.txt");
if (!file3.is_open()) {
std::cout << "Unable to open d3.txt" << std::endl;
return 1;
}
if (!file4.is_open()) {
std::cout << "Unable to open d4.txt" << std::endl;
return 1;
}
if (!outputFile2.is_open()) {
std::cout << "Unable to open d6.txt" << std::endl;
return 1;
}
std::string line3, line4;
while (true) {
string one,two;
if (std::getline(file4, line4)) {
// Read a line from file4
if (std::getline(file4, line4)) {
// Append the lines to outputFile2
appendLine(outputFile2, line3, line4);
} else {
// Reached the end of file4, exit the loop
break;
}
} else {
// Reached the end of file3, exit the loop
break;
}
}
while (std::getline(file3, line3)) {
appendLine(outputFile2, line3," ");
}
while (std::getline(file4, line4)) {
appendLine(outputFile2, line4," ");
}
file3.close();
file4.close();
outputFile2.close();
return 0;
}