Answer the question
In order to leave comments, you need to log in
Doesn't work inserted into a vector?
Good day! I'm doing term paper for uni. My words are a vector. But here's what's interesting when adding a new word to the vector of words, it crashes, and if 2 - 3 inserts work fine, but then it just crashes.
void Line::CreateNewWord( string character )
{
int i;
// Определение позиции итератора
for ( i = 0, it = words.begin(); it < words.end(); it++, i++)
if( i == activeWord )
break;
// Если не первое слово
if( width )
activeWord++;
// Создание нового слова
word = new Word();
word->Insert( character );
words.insert( it, *word );
width += FONT_WIDTH;
}
Answer the question
In order to leave comments, you need to log in
it<words.end();
oh, these lovers of global variables, their paws would be torn off .. and so - debug and look when you go beyond the vector, string or something else, and for the future - give up global variables and do more checks in methods in order to get rid of crashes and show the reasons why. By the way, catch it with a debugger, since you know that it is on 2-3 that the addition of the program breaks
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question