Stray '\342' in C++ Program

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

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

5

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"); 

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

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

Your Answer

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

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest