# C++: error: 'string' does not name a type

**Code:** `does not name a type` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

Where the compiler expected a type, it found a name it does not know as one — a missing header, namespace, or class declared later.

## Meaning

At global or class scope, the compiler only accepts declarations. An unknown word there is reported as "does not name a type". It usually means the type's header is missing, `std::` is missing, a typo, or the type is defined further down.

## Common causes

- Missing `#include <string>` / `<vector>` and similar
- Missing `std::` prefix at namespace or class scope
- Typo or wrong letter case
- Class used before its definition (needs a forward declaration)
- Statement placed at global scope (code outside any function)

## Quick fix

1. Add the header and `std::` prefix
2. Forward-declare the class or reorder definitions
3. Move statements into a function such as `main()`

## Detailed fix by platform

### C++

1. `#include <string>` then `std::string name;`
2. Check that code like `x = 5;` is inside a function, not at file level

## Code examples

### Statement outside a function

```cpp
#include <string>

std::string name;
name = "Ada";          // error: 'name' does not name a type (assignment at global scope)

int main() {
    name = "Ada";      // OK
}
```

## How to diagnose

1. **Scope** — Is this at file or class level?
2. **Header** — Is the type's header included?
3. **Order** — Is the type defined above this line?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/does-not-name-a-type)
