Stuck on passing an array to a struct (Solved)

Started by
11 comments, last by Adam Hamilton 17 years, 7 months ago
Quote:Original post by xeddiex
If you're using C, you would use strcpy and freinds.


You would never copy an array of this type with strcpy cause you would end up copying part of the array - up to the 0, the correct way to copy an char array would be to use memcpy. Friends are a C++ keyword.

Advertisement
Uh, I think he meant "and friends" in the colloquial sense of "and the other functions with similar names that do similar things." :P

Anyway, in C++, even when you think you need memcpy() or memmove(), you can still do much better: use std::copy() from <algorithm>.
I apologise... I typed that work so I guess the friend keyword was going through my mind.

There was nothing to indicate that the OP was using C++ and I was responding to the C strcpy comment. I do agree that if coding in C++ you would use std::copy

Edit: Oops... :( He would have been using C++ (the // gives it away) It's the little things you miss :P

This topic is closed to new replies.

Advertisement