1

Topic: Jobs under book Straustrup'

The silly person, cannot understand in what its error or more precisely cannot understand as it to solve.
Help please:
Started to do jobs under the book, decided to invent something interesting, but  on break point
Does not want to fulfill this if (pops [i] == words [i]) words [i] = "Beep";

#include <iostream>
#include <vector>
#include <string>
//#include <fstream>
#include <algorithm>
using namespace std;
int s;
vector <string> words, pops;
string temp;
int main () {
s = 2;
while (s! = 3) {
while (s == 1) {
cin>> temp;
words.push_back (temp);
for (int i = 0; i <= words.size (); i ++) {
if (temp == "Beepwords" || temp == "beepwords") s = 2;
if (temp == "Stop" || temp == "stop") s = 3;
if (pops [i] == words [i]) words [i] = "Beep";
}
}
while (s == 2) {
cin>> temp;
pops.push_back (temp);
for (int i = 0; i <= pops.size (); i ++) {
if (temp == "text" || temp == "Text") s = 1;
if (temp == "Stop" || temp == "stop") s = 3;
}
}
}
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])
cout <<words [i] <<"\n";
return 0;
}
 this 0x00ebd304 {asdasdad.exe!std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>> words} {size=1}
std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>> *

Wrote on VS 2017 Win 10 64x

2

Re: Jobs under book Straustrup'

pops [i] does not exist, an output for array boundaries.
PS How to make out messages

3

Re: Jobs under book Straustrup'

words [words.size ()] does not exist
It

for (int i = 0; i <= words.size (); i ++) {

It is necessary to write so

for (size_t i = 0; i! = words.size (); i ++) {

4

Re: Jobs under book Straustrup'

Dima T wrote:

pops [i] does not exist, an output for array boundaries.
PS How to make out messages

Thanks, I will read about design.
But how to make, that the program earned by such principle.
I enter into the first vector of a word which should be selected in a consequence from the second vector and change on "Beep".
It corrected both with words.size and with pops.size.

for (size_t i = 0; i! = words.size (); i ++) {

Now it turns out to write down the data in a vector words, but after a word "Stop" again I face on break points.
Can prompt please than and as it is possible to replace a line

if (pops [i] == words [i]) words [i] = "Beep";

5

Re: Jobs under book Straustrup'

Gossteer;
Enchanting .

6

Re: Jobs under book Straustrup'

Gossteer wrote:

But how to make, that the program earned by such principle.

Gradually. At first do tasks easier, then to this return.

7

Re: Jobs under book Straustrup'

Dima T, well.
Once again I thank.