File tree 3 files changed +38
-1
lines changed
3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ set(CXX_STANDARD_REQUIRED ON)
8
8
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
9
9
10
10
11
- add_subdirectory (WritingFile)
11
+ add_subdirectory (WritingFile)
12
+ add_subdirectory (ReadingFile)
Original file line number Diff line number Diff line change
1
+ project (ReadingFile)
2
+
3
+ add_executable (${PROJECT_NAME} main.cpp)
Original file line number Diff line number Diff line change
1
+ #include < fstream>
2
+ #include < iostream>
3
+ #include < regex>
4
+ #include < string>
5
+
6
+ int main (int argc, char **argv) {
7
+ if (argc < 2 ) {
8
+ std::cerr << " usage: " << argv[0 ] << " <filename>\n " ;
9
+ return 0x1 ;
10
+ }
11
+
12
+ std::ifstream *file = new std::ifstream ();
13
+
14
+ file->open (argv[1 ], std::ios::in); // open file with in mode
15
+
16
+ if (file->is_open ()) {
17
+ std::string data;
18
+
19
+ // read file until eof is hit
20
+ while (!file->eof ()) {
21
+ std::getline (*file, data);
22
+ std::cout << data << std::endl;
23
+ }
24
+ } else {
25
+ std::cerr << " Unable to open file \n " ;
26
+ }
27
+
28
+ file->close (); // close handle
29
+
30
+ delete file;
31
+ file = nullptr ;
32
+ return 0x0 ;
33
+ }
You can’t perform that action at this time.
0 commit comments