Have a function that parses a text file. Every time the function finds a match it saves the character number (position in the text file) to a vector<int>.
At the end of the program I print out all the locations of the successful matches between search-term and words-in-file.
The vector<int> I use to store the integer-locations of the foundwords is built using vectorname.push_back(charPosition).
However, on the FINAL box of the vector I get a negative integer value.
All the other boxes in the vector hold the accurate location of which character in the file the word was found on.
The very last vector box contains a negative number (should be character 145, is actually character -111).
Used a cout line to monitor that the values I'm feeding into the vector are accurate. Also used a cout line to monitor that the vector's last box doesn't change when I exit the function and pass the vector back to where it was declared in main();
Can you think of anything that would cause a vector<int> to receive incorrect integer values (from an int intname) or return incorrect integer values to where the vector or int was declared in main();?
(should be character 145, is actually character -111).
A positive value suddenly changing to a negative value is indicative of some sort of signed integer overflow. (256-145 = 111). So in some part of your code, it seems like it's trying to fit an int into a signed char, so it overflows. But note that this wrap around from a high positive number to a negative number is technically undefined behavior, and therefore cannot be relied upon. The wraparound, modulus behavior of unsigned ints (max unsigned integer + 1 == 0) can be relied upon, however.
Not sure why you're so resistant to sharing the code; you should be able to simplify your issue down to just a few lines, since you know which input values are causing the problems.
Turned out I had specified the int that tracked the number of matches as a 'char' by accident in the function definition.
When the 'char' (that was supposed to be an int) had to contain a number greater than 256 that char's maximum of 256 overflowed into negative numbers. So once the char had to handle numbers above 256 it started counting upwards, through negative numbers, towards zero.