0

Having this code

#include <vector>
#include <iostream>

using namespace std;

size_t num_break_points(const vector<unsigned  int> in_seq)
{
  vector<unsigned  int> in{ 0 };
  in.insert(in.end(), in_seq.begin(), in_seq.end());
  in.push_back(in_seq.size() + 1);

  size_t ret = 0;

  for (size_t i = 0; i < in.size() - 1; i++)
  {
    if (in[i + 1] - in[i] != 1)
      ret++;
  }
  std::cout << ret << " " << "Printed out variable x" << endl; 
  return ret;
}

int main(){
    vector<unsigned int> v { 3, 4, 5, −12, −8, −7, −6, 1, 2, 10, 9, −11, 13, 14 };
     num_break_points(v);
     return 0;
}

I am passing a vector to a function that has some negative ints, however I am getting

prog.cpp:23:5: error: stray ‘\342’ in program <br/>
     vector<unsigned int> v { 3, 4, 5, −12, −8, −7, −6, 1, 2, 10, 9, −11, 13, 14 }; <br/>
     ^ prog.cpp:23:5: error: stray ‘\210’ in program prog.cpp:23:5: error: stray ‘\222’ in program

What am I missing?

If I delete unsigned for vector definition, and make negative ints positive like:

#include <vector>
#include <iostream>
using namespace std;

size_t num_break_points(const vector<int> in_seq)
{
  vector<int> in{ 0 };
  in.insert(in.end(), in_seq.begin(), in_seq.end());
  in.push_back(in_seq.size() + 1);

  size_t ret = 0;

  for (size_t i = 0; i < in.size() - 1; i++)
  {
    if (in[i + 1] - in[i] != 1)
      ret++;
  }
  std::cout<<ret<<" "<<"Printed out variable x"<<endl; 
  return ret;
}

int main(){
    vector< int> v {3, 4, 5, 12, 8, 7, 6, 1, 2, 10, 9, 11, 13, 14};
    num_break_points(v);
    return 0;
}

I get:

10 Printed out variable x

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
  • 3
    Did you copy and paste from an ebook, try manually replacing the `-` symbols. Then you will run into a narrowing conversion error though since the vector is *unsigned int* and negative numbers are clearly not unsigned. – Shafik Yaghmour Dec 31 '13 at 16:54
  • A much more direct analysis is to realise ‘\342’ ‘\210’ ‘\222’ are octal → UTF-8 byte sequence 0xE2 0x88 0x92 → [U+2212 − MINUS SIGN](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128) (in a place with mathematical symbols, like ∀, ∇, ∏, ∑, ∞, and ∬) – Peter Mortensen Mar 05 '21 at 10:57
  • 1
    This is a duplicate. The canonical is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Mar 05 '21 at 10:59
  • Does this answer your question? [Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332/compilation-error-stray-302-in-program-etc) – Karl Knechtel Jan 16 '23 at 14:33

2 Answers2

2

This error message means, that you have an invalid character on the line initializing the vector. Possibly - is not the correct -, e.g. if you copied this line it may be some UTF-8 character.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sebastian
  • 8,046
  • 2
  • 34
  • 58
1

Your '-' is not an actual minus. You probably copied from a PDF, or e-book.

Also, using negative values will cause narrowing for v as vector<unsigned int>.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
P0W
  • 46,614
  • 9
  • 72
  • 119