# C/C++: error: stray '\342' in program (smart quotes or invisible characters)

**Code:** `stray in program` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

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.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/stray-character-in-program)
