C++: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
C++ forbids silently dropping const or converting between unrelated pointer types — typically a string literal assigned to char*.
invalid conversion from 'const char*' to 'char*'invalid conversion from 'void*' toISO C++ forbids converting a string constant to 'char*'deprecated conversion from string constant 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 ofconst 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
- Use
const char*orstd::string - Use
static_cast<T*>(malloc(n))— or betternew/std::vector - Make the function parameter
constinstead of casting away const
Detailed fix by platform
C++
- Replace
char* name = "x";withconst char* name = "x";orstd::string name = "x"; - For a C API that wants
char*, copy into astd::vector<char>and pass.data()
Code examples
const-correct string handling
// 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 castHow to diagnose
- Source — Is the right-hand side a literal or a const object?
- Target — Can the variable type be made const?
- Language — Was this file meant to be compiled as C?
🔧 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
- comparison of integers of different signs C/C++: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' [-Wsign-compare]
- discards qualifiers C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive]
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