2

Possible Duplicate:
Xcode gives 3 syntax errors dealing with Stray ‘\342’ in program

if(mGamma[i−1][j] == min(mGamma[i − 1][j], mGamma[i][j − 1], mGamma[i − 1][j − 1]))

The line above gives me these errors:

/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\210’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\222’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\342’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\210’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\222’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\342’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\210’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\222’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\342’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\210’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\222’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\342’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\210’ in program
/home/rajat/iCub/tutorials/src/vectordtw.h:91:3: error: stray ‘\222’ in program

Where mGamma is defined as vector<vector<double> > mGamma and the min function takes three values and returns the minimum. Where do these errors come from, and how do I get rid of them?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rajat
  • 3,415
  • 15
  • 56
  • 90
  • what text editor are you using? – Aniket Inge Nov 05 '12 at 00:42
  • I have faced these problems with Vim – Aniket Inge Nov 05 '12 at 00:44
  • i am using gedit , but i pasted the pseudo code from a pdf and then changed it to C++ – rajat Nov 05 '12 at 00:45
  • Then that's where the problem lies. You might have to type each line then. copying from a PDF will not help(and then again, there is that encoding problem). Maybe the PDF text is using a different encoding that isn't supported by gcc? – Aniket Inge Nov 05 '12 at 00:46
  • 1
    The problem characters are every minus sign, so yeah, it's the same as the earlier question @JeremiahWillcock found. – zwol Nov 05 '12 at 00:46
  • Ohk , Thanks . I wrote the lines myself and that solved the problem . – rajat Nov 05 '12 at 00:47
  • I think you left out the first stray error, \342. 342 210 222 (octal) → 0xE2 0x88 0x92 (hexadecimal) → UTF-8 sequence for Unicode code point U+2212 ([MINUS SIGN](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). Most text editors (e.g. [Geany](https://en.wikipedia.org/wiki/Geany) (Linux and Windows) and [Notepad++](https://en.wikipedia.org/wiki/Notepad%2B%2B)) with a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) mode will be able to do search/replace for Unicode code point U+2212, using `\x{2212}`. – Peter Mortensen Mar 06 '21 at 21:55
  • Note: The notation is different in Visual Studio Code (and probably others): `\u2212` (instead of `\x{2212}`) – Peter Mortensen Apr 27 '23 at 15:24
  • The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 27 '23 at 15:25

1 Answers1

4

That error message means that there are bytes in the file that don't correspond to any character the compiler understands, so it's printing out their octal values and telling you that this can't possibly be a valid C(++) program.

The byte sequence you show appears to be the UTF-8 encoding of U+2212 MINUS SIGN. Despite this being the "appropriate" character to use for a minus sign in "proper" Unicode text (which is why it's copying out of a PDF that way), the C family's "basic source character set" remains ASCII-centric; you need to replace each of those minus signs with U+002D HYPHEN-MINUS. Typing over each with a minus sign, as you normally would type it, should do the trick.

zwol
  • 135,547
  • 38
  • 252
  • 361
  • the problem is solved. I don't understand the need to answer this question. – Aniket Inge Nov 05 '12 at 00:50
  • 3
    Even if the problem is solved, writing out a clear answer may help the next person to trip over the same problem. This is the case *even if* an "exact duplicate" has been identified, because everybody describes problems and solutions a little differently, so having multiple variations on the same question increases the odds that the next person will recognize that this is their problem. – zwol Nov 05 '12 at 00:56