I'm trying to make a dictionary in C++ but am having trouble splitting a text file on an '=' delimiter. Ideally it would be in an array of two. I want to take the left side of the '=' of the line into array[0] and the right side into array[1] and then use array[0] as the key and array[1] as the value through a premade insert function eg. dictionary.insert(array[0], array[1]). I've already built the dictionary logic but am having trouble splitting the lines.
Here's my (terrible) code that is not using the equal sign as the delimiter and therefore putting the '=' into array[1]:
int main() {
Dictionary englishToEsperanto;
ifstream infile("Dictionary.txt");
string line;
string arr[2];
if (infile.is_open())
{
while (getline(infile, line))
{
int i = 0;
stringstream ssin(line);
while (ssin.good() && i < 2) {
ssin >> arr[i];
++i;
}
for (i = 0; i < 2; i++) {
cout << arr[i] << ' ';
}
cout << endl;
}
infile.close();
}
else
{
cout << "Error opening file";
}
return 0;
}
Here's the first few lines of the text file:
aback, to take = surprizi.
abaft = posta parto.
abandon = forlasi.
abase = humiligi. [error in book: humilgi]
abash = hontigi.
abate (lower) = mallevi.
abate (speed) = malakceli.
abbey = abatejo.
abbot = abato.
abbreviate = mallongigi.
abdicate = demeti la reĝecon.
abdomen = ventro.
Thanks for looking.