-
Notifications
You must be signed in to change notification settings - Fork 1
/
output.h
39 lines (31 loc) · 839 Bytes
/
output.h
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
#ifndef OUTPUT_H
#define OUTPUT_H
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void Output1(string str) {
string filename = "output.txt";
ofstream outfile;
// Check if the file exists
ifstream infile(filename.c_str());
if (infile.good()) {
// Check if the string is already in the file
string line;
while (getline(infile, line)) {
if (line == str) {
return; // Exit the function without writing
}
}
// Open the file in append mode
outfile.open(filename.c_str(), ios::app);
} else {
// Create the file and open it in write mode
outfile.open(filename.c_str());
}
// Write to the file
outfile << str << "\n";
// Close the file
outfile.close();
}
#endif