I am writing a program that reads a file and puts the contents into a map. The contents of the file are something like: A 1 B 3 C 3 D 2 etc.. basically its just the letters of the alphabet and their scrabble values. I got the contents of the file into the map and it works but I am trying to call the map from a string variable that is given a value before. This is the code I have right now so you can see.
#include <algorithm>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <unordered_map>
int main() {
std::vector<std::string> scrabble;
{
std::ifstream scrabble_words("/srv/datasets/scrabble-hybrid");
for (std::string word; std::getline(scrabble_words, word);) {
scrabble.push_back(word);
}
}
int word_count = 0;
std::string word;
for (word; std::cin >> word;) {
std::for_each(word.begin(), word.end(), [](char& c) { c = ::toupper(c); });
if (std::find(scrabble.begin(), scrabble.end(), word) != scrabble.end()) {
word_count++;
}
}
std::unordered_map<std::string, int> points;
std::string letter;
std::ifstream in_file("/srv/datasets/scrabble-letter-values");
for (int worth; in_file >> letter >> worth;) {
points[letter] = worth;
}
std::cout << points[word[1]] << '\n';
I am trying to access the contents of the map through the characters in the variable that is set before:
std::cout << points[word[1]] << '\n';
but when I try to call it like this I get pages of error messages that I can't understand and I can't figure out how to get this to work. I am pretty sure it is because the type of word[1] is different from the type of letter but I don't know how to get around this.