Need some help with a problem :).

I am going through Bjarne Stroustrup's book and I have encountered a problem that i cannot solve. I get a lot of errors. I know I messed it up. I would really appreciate if someone could look at it a bit to see if they can help.


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
  #include "P:\C++\Exercitii si Drills\Drills\pg . 75\std_lib_facilities.h"

using namespace std;

int main()
{
   vector<string> dislike = {"Dislike", "Alike", "Hello", "Water"}

   vector<string> words;

   cout << "Please enter some words.\n";

   for(string word;cin >> word;)

     words.push_back(word);

   sort(words);

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

    if(i==0 || words[i-1]!==words[i]){

        if(words[i]!=dislike[i]){

            cout << words[i] << '\n';
        else
            cout << "BLEEP" '\n';
      }
    }
  }
  cout << words.vector;

}


Line 15: error: "words" was not declared in this scope
Line 17: error: "words" was not declared in this scope
Line 21: error: expected primary-expression before '=' token
Line 26: error: expected '}' before 'else'
Line 27: error: expected ';' before '\xa'
Line 31: error: 'cout' does not name a type
Line 34: error: expected declaration before '}' token

One more, it has something to do with std_lib_facilities.h:
Line 352: error: exprected',' or ';' before 'Vector'
Last edited on
I can't stand when textbooks want to include random crap instead of just listing the actual Standard Library includes.

1
2
3
4
#include <algorithm>  // std::sort()
#include <iostream>   // std::cin, std::cout
#include <string>     // std::string
#include <vector>     // std::vector 

I see three errors:

1)"dislike" vector need a terminating semicolon.
2)!== in "words[i-1]!==words[i]" is not a valid comparison operator, use !=
3)cout << words.vector; is not a valid declaration, the vector<string> words has no member variable called vector
Replace it with
1
2
for(auto& word : words){   cout << word << ", ";  }
cout << endl;


I didn't looked for logic errors in the program though, only syntax
Last edited on
Topic archived. No new replies allowed.