-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileutils.cpp
More file actions
40 lines (35 loc) · 776 Bytes
/
Copy pathFileutils.cpp
File metadata and controls
40 lines (35 loc) · 776 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
#pragma once
#include "Fileutils.h"
/*
* Iterate through all the lines in file and
* put them in given vector
*/
size_t getFileContent(std::string fileName, std::vector<std::string> & vecOfStrs)
{
// Open the File
std::ifstream infile(fileName.c_str());
// Check if object is valid
if (!infile)
{
throw std::runtime_error("Cannot open Control File");
}
std::string str;
auto total=0;
// Read the next line from File until it reaches the end.
while (std::getline(infile, str))
{
// Line contains string of length > 0 then save it in vector
if (str.size() > 0)
{
vecOfStrs.push_back(str);
total++;
}
}
if (vecOfStrs.empty())
{
throw std::runtime_error("No Items found in File");
}
//Close The File
infile.close();
return (total);
}