Nov 25, 2017 at 1:03pm UTC
You are trying to alter a const. In main str should be defined as const char * = "Bill" ;
.
Nov 25, 2017 at 1:07pm UTC
thanks jlb
but how am I trying to alter a const?
I never declared str as const?
Nov 25, 2017 at 1:47pm UTC
Because "Bill" is a const and you're playing with a pointer, not an array of char.
You should have gotten a warning/error if you're using a properly configured modern compiler something like:
main.cpp|17|error: ISO C++ forbids converting a string constant to ‘char*’ [-Wpedantic]|
The other option would be to use an array instead of the pointer:
char str[] = "Bill" ;
Remember there are subtle differences between arrays and pointers.
By the way why are you using C-strings instead of std::string?
Nov 25, 2017 at 2:55pm UTC
Thanks guys I never knew that
yeah would be a better idea to use std::string but I'm just playing around with c style strings