이것은 지금까지 제 프로그램입니다. 그것은 컴파일되지만 마지막 부분에서 멈추고 충돌합니다. 나는 사용자의 문자열 입력을 반복하고 문자열에서 발견 된 잘못된 단어를 "****"로 대체하려고합니다. 내 오류는 find_Poop_inSentence에있을 가능성이 큽니다. "디버그 어설 션이 실패했습니다. 벡터 첨자 범위를 벗어"사용자 입력을 벡터에 저장된 값과 비교하십시오.
void find_Poop_inSentence(vector<string> & v1, vector<string> & v2, string sub);
int main()
{
cout << "Howdy partner, tell me some words you don't take kindly to.\n";
vector<string>bad_words;
string word;
while (cin >> word)
{
cin.ignore();
bad_words.push_back(word);
if (word == "exit")
break;
}
cout << "Ok partner, got it!\n";
cout << "Now say something and I'll repeat it back to you. Don't worry, I'll bleep out the words that you don't like.\n";
word = "";
vector<string> random_sentence;
while (cin >> word)
{
cin.ignore();
random_sentence.push_back(word);
if (cin.get() == '\n')
break;
}
find_Poop_inSentence(bad_words, random_sentence, "****");
cout << "You said: ";
for (unsigned int i = 0; i < random_sentence.size(); ++i) {
cout << ' ' << random_sentence[i];
}
system("Pause");
return 0;
}
void find_Poop_inSentence(vector<string> & v1, vector<string> & v2, string sub) {
int iterOne;
int iterTwo = 0;
int iteratorMax = v2.size();
for (iterOne = 0; iterOne < iteratorMax; iterTwo++) {
if (v1[iterOne] == v2[iterTwo]) {
v2[iterTwo] == sub;
}
if (iterTwo == iteratorMax) {
iterOne++;
iterTwo = 0;
}
}
}
fml. 편집하고 재 게시합니다. 죄송합니다. 많은 수면없이이 일을하고 있었고 뇌가 아팠습니다. 응답을 위해 ty – Ranfan
는 편집하는 데 잠시 걸렸다. 그러나 나는 아직도 나빠져있다 – Ranfan
나는 당신의 고무 오리와 말했어, 내가 제안했던 것에 따라? –