Problem with std::map and txt file reading

Hello there!

I have a problem with my code, I mean...
I used std::map container to sort letters in alphabetical order and assign them number of their position in the alphabet (A-1, Z-26)
Now I should read word from txt file
string of numbers: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
(for example: SKY is 19 + 11 + 25 = 55 = t10) --^^--
but there is so many words and my program exacly reads this word and its value-number, but ENTER in notepad is written in my console as a '->' and have stupid values like 1970795730, or just 8.
Have you any idea how to ignore this arrow sign?
link to my code: https://pastebin.com/aLFEt4uA
link to the task: https://projecteuler.net/problem=42

Before using the iterator that is returned from alphabet.find(singleLetter) you probably want to check that the character was actually found by comparing it to alphabet.end().

1
2
3
4
5
auto it = alphabet.find(singleLetter);
if (it != alphabet.end())
{
	// singleLetter was found in alphabet
}
Im using C++11 :/ and I don't understand what do you mean :(
I just want to know how to ignore this '->' arrow which my compiler reads as a new line in notepad
Last edited on
Not sure what newlines you're talking about. p042_words.txt does not contain a single newline character.

If the problem is that your program outputs crazy characters I thought it could be because you didn't check the return value of find before using it. The file contains commas ',' and quotation marks '"' and these characters are not part of alphabet so when you try to find them you will get back alphabet.end() to let you know it was not found. alphabet.end() does not refer to a valid element in the map so trying use it to access first or second could lead to unpredictable results.
Last edited on
Topic archived. No new replies allowed.