-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportkey.cpp
44 lines (36 loc) · 1.08 KB
/
importkey.cpp
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
41
42
43
44
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
//all functions for importing key file
class KeyReader{
public:
//import key, only line 1 of txt file is read
std::string importKeySL(std::string fileName){
std::ifstream txtFile(fileName);
if(!txtFile.is_open()){
std::cerr << "Unable to open file\n";
}
//read 1st line (remaining lines ignored)
std::string fileContent;
std::getline(txtFile,fileContent);
txtFile.close();
return fileContent;
}
//import key, all lines -> vector
std::vector<std::string> importKeyML(std::string fileName){
std::vector<std::string> vec;
std::ifstream txtFile(fileName);
if(!txtFile.is_open()){
std::cerr << "Unable to open file\n";
return vec; //empty
}
//read + append each line to vector
std::string fileContent;
while(std::getline(txtFile,fileContent)){
vec.push_back(fileContent);
}
txtFile.close();
return vec;
}
};