-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread.cpp
More file actions
94 lines (85 loc) · 2.07 KB
/
read.cpp
File metadata and controls
94 lines (85 loc) · 2.07 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include "Dog.h"
using namespace std;
int addToDog(string str);
int main()
{
string line;
string formatted;
vector<string> unparsed;
ifstream myfile;
myfile.open("dogs.txt");
cout << "Attempting open" << endl;
cout << myfile.is_open() << endl;
if (myfile.is_open())
{
cout << "File has been opened" << endl;
cout << "Is file good?" <<myfile.good() << endl;
while (myfile.good())
{
cout << "Attempting to read from file" << endl;
getline(myfile, line);
cout << line << '\n';
unparsed.push_back(line);
addToDog(line);
}
myfile.close();
cout << "File has been closed" << endl;
}
else cout << "Unable to open file";
cout << unparsed.size() << " lines have been read in." << endl;
return 0;
}
/*
addToDog(string str)
Precondition: A string containing the data to be stored within the Dog class
Postcondition: Creates a new object of class Dog and then return it. Does not Happen!
Notes: temporary not ment for linked list
*/
int addToDog(string str)
{
int stringSize;
int segmentNo = 0;
string temp = "";
string segment[6];
//Dog aDog; //not working for some reason claims no default constructor
map<char, int> ignore; //0 = ignore character, 1 = end of segment, 2 stop reading
ignore['<'] = 0;
ignore['>'] = 2;
ignore['/'] = 2;
ignore[','] = 1;
for (int i = 0; i < str.length(); i++)
{
char ch = str.at(i);
//cout << "ignore count is" << ignore.count(ch) << endl;
if (ignore.count(ch) < 1)
{
temp += ch;
//cout << "adding " << ch << " ";
} //adds char to temporary string for that particular segment
else
{
int instruction = ignore.find(ch)->second;
switch (instruction)
{
case 0: //ignores that particular character.
break;
case 1: //moves onto next segment.
cout << temp << endl;
segment[segmentNo] = temp;
segmentNo++;
cout << "Segment has been successfully added." << endl;
temp = ""; //empties temp
//aDog.addData(temp);
break;
case 2:
return 0;
}
}
}
return 0;
}