-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.cpp
More file actions
executable file
·41 lines (34 loc) · 857 Bytes
/
check.cpp
File metadata and controls
executable file
·41 lines (34 loc) · 857 Bytes
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
// Check if filename is provided as argument
if (argc != 2)
{
cerr << "Usage: " << argv[0] << " <filename>" << endl;
return 1;
}
// Concatenate filename with ".txt"
string filepath = string(argv[1]) + ".txt";
// Open the file
ifstream file(filepath);
// Check if the file is opened successfully
if (!file.is_open())
{
cerr << "Error: Unable to open file." << endl;
return 1;
}
// Read the file line by line
string line, filecontent;
int i = 0;
while (getline(file, line))
{
filecontent += line;
}
// Close the file
file.close();
cout << "At the end, the final text is:\n " << filecontent << endl;
return 0;
}