"This application has requested the run-time terminate in an unusual way."
I am freelance trying to run through Stroustrups principles and practice in c++ programming book. this specific program which is designed to give you back all the words that you input in order in a list in order, terminating repeated words.
This is the initial code for this simple program. (not including libraries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
int main()
{
vector<string> words;
string word;
while (cin>>word)
words.push_back(word); // add entered strings to the vector
cout << "Number of words: " << words.size() << endl;
sort(words.begin(),words.end());
for (int i = 0; i<words.size(); ++i)
if (i==0 || words[i-1]!=words[i] ) // is this a new word?
cout << words[i] << endl;
system("PAUSE");
}
|
This works fine and i have no problems with it, you input some words and then you press enter and on then press ctrl+z which isnt recognized as a string so it terminates the loop and performs the for loop.
--------------------------------------------------------------------------------
So here is the real issue.
In the book he asks you to "TRY THIS!" where he says that you should try to make a program that does what this does, but add on some code which would make it so that if any undesirable words were uttered, they would be bleeped out..
i think i may have failed miserably but ill explain my "logic" for trying to get this to work. If im terribly wrong then maybe someone could point me in a better direction for accomplishing this.(this isnt some homework assignment of mine dont worry, i do this for fun)
Here is my guess at a program that can censor unwanted words.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
vector<string> words;
string word;
string badword = "bananas";
string goodword = 0;
cout << "This program records every word you type and records them in order."
<< endl
<< "This program will also bleep out any unlike words."
<< endl
<< "What word would you like to have replace any bad words?"
<< endl
<< "------>";
cin >> goodword;
cout << "go!";
while (cin>>word)
words.push_back(word); // add entered strings to the vector
cout << "Number of words: " << words.size() << endl;
sort(words.begin(),words.end());
for (int i = 0; i<words.size(); ++i)
if (i==0 || words[i-1]!=words[i] || words[0,word.size()]== badword) { // is this a new word?
badword = goodword;
cout << words[i] << endl;
}
system("PAUSE");
}
|
Basically my thoughts here were this..
I declared some string variable named badword and defined it with the string "bananas". so if bananas is input its turned into a "goodword"
Then i declared an empty variable named "goodword"
I give the user some directions then prompt him to give a word that would replace "badword" with "goodword"
at the end i added another condition which was that if any of the words in the vector from range 0 to words.size() = badword then it would change it to the good word..
the program will run and the console comes up but it stops responding and gives a terminating error and prompts me to locate the application team (me) for any questions lol.
even though im not sure that would work at all just a guess. im very new to programming.
Any hints or tips would be nice sorry if this is extremely noob or seems like a dumb question to any of you, im just learning.