-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfilecheck.cpp
More file actions
41 lines (37 loc) · 924 Bytes
/
filecheck.cpp
File metadata and controls
41 lines (37 loc) · 924 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
#include "filecheck.h"
#include <iostream>
static bool getString(std::ifstream& fin, const char* mesg)
{
std::streampos position;
std::string line;
position = fin.tellg();
while (getline(fin, line))
{
if (line.find(mesg) != std::string::npos)
{
char ch;
fin.seekg(-1, std::ios_base::cur);
while (fin.get(ch) && ch != ':')
fin.seekg(-2, std::ios_base::cur);
fin.seekg(1, std::ios_base::cur);
return true;
}
}
fin.clear();
fin.seekg(position);
return false;
}
bool findAndLocate(std::ifstream& fin, const char* mesg)
{
std::cout << mesg << " ";
if (!getString(fin, mesg))
{
fin.seekg(0);
if (!getString(fin, mesg))
{
std::cout << "Can't find string " << mesg << " in file!\n";
return false;
}
}
return true;
}