17

I'm getting these errors in my program after pasting in some code:

showdata.cpp:66: error: stray ‘\342’ in program
showdata.cpp:66: error: stray ‘\200’ in program
showdata.cpp:66: error: stray ‘\235’ in program
showdata.cpp:66: error: stray ‘\’ in program
showdata.cpp:66: error: stray ‘\342’ in program
showdata.cpp:66: error: stray ‘\200’ in program
showdata.cpp:66: error: stray ‘\235’ in program
showdata.cpp:67: error: stray ‘\342’ in program
showdata.cpp:67: error: stray ‘\200’ in program
showdata.cpp:67: error: stray ‘\235’ in program
showdata.cpp:67: error: stray ‘\’ in program
showdata.cpp:67: error: stray ‘\342’ in program
showdata.cpp:67: error: stray ‘\200’ in program
showdata.cpp:67: error: stray ‘\235’ in program

Here are the two lines that are causing the errors.

size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);

How can I fix this?

3

4 Answers 4

46

The symbol is not ". Those are called 'smart quotes' and are usually found in rich documents or blogs.

5
  • 8
    I think some one is using Word as an IDE ;)
    – leppie
    Feb 26, 2010 at 10:48
  • 11
    Or copy-pasting code from blogs. Whatever it is, it's not our place to criticise it.
    – LiraNuna
    Feb 26, 2010 at 10:59
  • It happened to me... I had my old Turbo/Borland C (3.1) code documented on Word. To check if some of them were compatible with GCC/G++ I pasted selected portions from the DOC file to GEdit. And there it was... And the worst part is that I never noticed this change until I saw this answer... Hmmm maybe I'm getting old :)
    – itsols
    Apr 20, 2013 at 14:12
  • This happens when you use "shift+enter" in some editors
    – Ari
    Nov 20, 2017 at 22:42
  • It is Unicode code point U+201D (RIGHT DOUBLE QUOTATION MARK). Most text editors (e.g. Geany (Linux and Windows) and Notepad++) with a regular expression mode will be able to do search/replace for Unicode code point U+201D, using \x{201D}. Mar 6, 2021 at 21:09
6

The lines

 size_t startpos = str.find_first_not_of(” \t”); 
 size_t endpos = str.find_last_not_of(” \t”); 

have some "special" kind of double quotes, try the following:

 size_t startpos = str.find_first_not_of(" \t"); 
 size_t endpos = str.find_last_not_of(" \t"); 
4

This sort of error message, error: stray ‘\xyz’ in program, can appear with any other character or symbol that is not recognized by the compiler as a legal one.

Sharing my personal experience:

 - bool less<const char∗>(const char∗ a, const char∗ b)
 - bool less<const char*>(const char* a, const char* b)

The former one is copy-pasted from a PDF file. It doesn't compile.

The latter one compiles as expected.

0
0

You can use the sed command to fix these issues.

This will give you a quick preview of what will be replaced.

sed s/[”“]/'"'/g File.txt

This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt.

sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt

This will overwrite the original file.

sed -i ".bk" s/[”“]/'"'/g File.txt

2
  • I don't think you should have a space between -i and .bk - GNU sed (at least) will interpret them separately (i.e. "in-place with no backup file" and a command that's a syntax error). Mar 1, 2017 at 17:37
  • How do you type the slanted and inverted slanted double quotes on a keyboard? (in linux)
    – Ribo
    Jan 10, 2019 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.