Char Pointer troubles

This is a really stupid question.. I know.. but I've forgotten how to do this exactly.


char *ptr = new char[10];

*ptr = "Foo";


This is totally not right, but I can't remember what the proper way to assign a string into an array through a pointer is. Any help is greatly appreciated. Thank you for your time.
You can use std::strcpy from the <cstring> header.

std::strcpy(ptr, "Foo");
Last edited on
Yeah, I found I could also use memcpy(), but I thought there was a way to do it with an assignment operator. Thanks for the reply!
If you've already used new, you can't just use the = operator.

You can however, do this:

const char* ptr = "Foo";
Thank you! I thought that might be the case.. been so long since I needed to do this. Lol. Thanks all!
Topic archived. No new replies allowed.