stray in program C/C++ Origin: Application & API Last updated 15 Oct 2026

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.

Exact message you may see stray '\342' in programstray '\302' in programstray '\240' in programstray '\\' in programnon-ASCII character in source
Seen on: C/C++ GCC Clang

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

  1. Retype the quotes and spaces as plain ASCII
  2. Search the file for non-ASCII bytes (command below)
  3. Turn on "render whitespace" in your editor

Detailed fix by platform

Linux

  1. Find the culprits: grep -nP '[^\x00-\x7F]' main.cpp
  2. Strip them from the line shown in the error

Editor

  1. In VS Code use "Unicode Highlight" or Find with the regex [^\x00-\x7F]

Code examples

Smart quotes break the build

cpp
// Pasted from a blog post (curly quotes):
// printf(“Hello\n”);          // error: stray '\342' in program

printf("Hello\n");             // straight ASCII quotes

How to diagnose

  1. Byte — Octal value in the message?
  2. Location — Which line and column?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…expected ';' before — C/C++: error: expected ';' before 'x' — missing semicolon (C/C++)expected ';' beforeexpected primary-expression before — C++: error: expected primary-expression before ')' token (C/C++)expected primary-expr…expected unqualified-id before — C++: error: expected unqualified-id before 'return' / before ')' token (C/C++)expected unqualified-…need typename before dependent name — C++: error: need 'typename' before 'T::iterator' because 'T' is a dependent scope (C/C++)need typename before …was not declared in this scope — C++: error: 'x' was not declared in this scope (undeclared identifier) (C/C++)was not declared in t…stray in …

Explore the map of this error Full error map →

🧠 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.