C/C++: error: stray '\342' in program (smart quotes or invisible characters)
The source file contains a character the compiler does not recognise, typically curly quotes or a non-breaking space pasted from a web page or document.
stray '\342' in programstray '\302' in programstray '\240' in programstray '\\' in programnon-ASCII character in source Meaning
Word processors, chat apps and some websites replace straight quotes with “ ” and ‘ ’, and add non-breaking spaces. GCC prints the first byte of the UTF-8 sequence in octal (\342\200\234 is “). Replace them with ASCII equivalents and use a code editor.
Common causes
- Curly quotes “ ” ‘ ’ pasted from a document or web page
- Non-breaking space (U+00A0) or zero-width space in the code
- En/em dash used instead of a minus sign
- Unicode ellipsis … or full-width punctuation
⚡ Quick fix
- Retype the quotes and spaces as plain ASCII
- Search the file for non-ASCII bytes (command below)
- Turn on "render whitespace" in your editor
Detailed fix by platform
Linux
- Find the culprits:
grep -nP '[^\x00-\x7F]' main.cpp - Strip them from the line shown in the error
Editor
- In VS Code use "Unicode Highlight" or Find with the regex
[^\x00-\x7F]
Code examples
Smart quotes break the build
// Pasted from a blog post (curly quotes):
// printf(“Hello\n”); // error: stray '\342' in program
printf("Hello\n"); // straight ASCII quotesHow to diagnose
- Byte — Octal value in the message?
- Location — Which line and column?
- Source — Was the code pasted from a web page?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- call of overloaded is ambiguous C++: error: call of overloaded 'f(int)' is ambiguous
- cannot declare variable to be of abstract type C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions)
- expected ';' before C/C++: error: expected ';' before 'x' — missing semicolon
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026