forked from Thaddad/LearningC2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw_getfile.cpp
More file actions
35 lines (28 loc) · 725 Bytes
/
hw_getfile.cpp
File metadata and controls
35 lines (28 loc) · 725 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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
//~~~~~for entire line, change cout<<word to cout line
//~~~~~~~~~~~~~~~~~~~~prints line from target word on.
int main(int argc, char* argv[]){
//for (int i = 0; i<argc; i++)
string word = string(argv[1]);
string line;
string fileName = "meals.txt";
ifstream infile (fileName.c_str());
if (infile.good() == false){
cout << "unable to open the file name." << fileName;
exit(1);
}
while(true) {
getline(infile, line);
size_t pos = line.find(word);
if (pos == 2){
string word = line.substr(pos);
cout << word << endl;
}
if(infile.eof()) break;
}
return 0;
}