cplusplus:file_processing_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cplusplus:file_processing_examples [2017/02/08 20:51] – [Simple example] mithat | cplusplus:file_processing_examples [2017/02/08 20:54] – [Read all tokens in a file] mithat | ||
---|---|---|---|
Line 139: | Line 139: | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include <cstring> | + | #include <string> |
using namespace std; | using namespace std; | ||
Line 175: | Line 175: | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include <cstring> | + | #include <string> |
using namespace std; | using namespace std; | ||
Line 183: | Line 183: | ||
int num1; | int num1; | ||
- | ifstream infile; | + | ifstream infile; |
- | infile.open(filename.c_str()); // associate file with file pointer object | + | infile.open(filename); |
if (!infile) | if (!infile) | ||
- | cerr << "Error opening file." << endl; | ||
- | else | ||
{ | { | ||
- | cout << "Reading from file ... " << endl; | + | cout << "Error opening |
+ | return 1; // exit program with error code | ||
+ | } | ||
- | while (infile >> num1) | + | |
- | { | + | |
- | | + | |
- | } | + | |
- | infile.close(); | + | |
- | | + | while (infile >> num1) |
+ | { | ||
+ | | ||
} | } | ||
+ | infile.close(); | ||
+ | |||
+ | cout << " | ||
return 0; | return 0; | ||
} | } | ||
</ | </ |
cplusplus/file_processing_examples.txt · Last modified: 2019/02/11 19:17 by mithat