-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestFD.cpp
70 lines (49 loc) · 1.14 KB
/
testFD.cpp
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
/*
* testFD
* Date: May-04-2022
* Author : Gabriel Renaud gabriel.reno [at sign here ] gmail.com
*
*/
#include <iostream>
#include <fstream>
using namespace std;
int writeNumbers(const string & filename){
ofstream oFile;
oFile.open(filename.c_str(), ios::out);
if (oFile.is_open()){
for(int i=1;i<11;i++)
oFile<<i<<endl;
oFile.close();
return 0;
}else{
cerr << "Unable to write to file "<<filename<<endl;
return 1;
}
}
int rwDoubleNumbers(const string & filenamein,const string & filenameout){
string line;
ifstream iFile;
ofstream oFile;
iFile.open(filenamein.c_str(), ios::in);
oFile.open(filenameout.c_str(), ios::out);
if (!iFile.is_open()){
cerr << "Unable to open file "<<filenamein<<endl;
return 1;
}
if (!oFile.is_open()){
cerr << "Unable to write to file "<<filenameout<<endl;
return 1;
}
while(getline (iFile,line)){
int i=stoi(line);
oFile<<(i*2)<<endl;
}
iFile.close();
oFile.close();
return 0;
}
int main (int argc, char *argv[]) {
writeNumbers("numbers.txt");
rwDoubleNumbers("numbers.txt","double.txt");
return 0;
}