# C++: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

**Code:** `invalid conversion from` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

C++ forbids silently dropping `const` or converting between unrelated pointer types — typically a string literal assigned to `char*`.

## Meaning

In C++ a string literal has type `const char[N]`, so `char* s = "hi";` is ill-formed. The same rule applies to `void*` (needs a cast in C++) and to `int` to enum conversions. The fix is to make the target type const-correct, not to add `-fpermissive`.

## Common causes

- String literal assigned to `char*` instead of `const char*`
- `void*` from malloc assigned without a cast (valid in C, not C++)
- const object passed where a non-const pointer is required
- Integer assigned to an enum or pointer type
- C code compiled as C++

## Quick fix

1. Use `const char*` or `std::string`
2. Use `static_cast<T*>(malloc(n))` — or better `new`/`std::vector`
3. Make the function parameter `const` instead of casting away const

## Detailed fix by platform

### C++

1. Replace `char* name = "x";` with `const char* name = "x";` or `std::string name = "x";`
2. For a C API that wants `char*`, copy into a `std::vector<char>` and pass `.data()`

## Code examples

### const-correct string handling

```cpp
// error: invalid conversion from 'const char*' to 'char*'
// char* title = "Report";

const char* title = "Report";          // OK: read-only literal
std::string editable = "Report";       // OK: owns a copy

void* raw = std::malloc(16);
int* p = static_cast<int*>(raw);       // C++ needs the cast
```

## How to diagnose

1. **Source** — Is the right-hand side a literal or a const object?
2. **Target** — Can the variable type be made const?
3. **Language** — Was this file meant to be compiled as C?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/invalid-conversion-from-const-char)
