Skip to main content
added 91 characters in body
Source Link
Benjamin Lindley
  • 104.2k
  • 11
  • 210
  • 285

If your compiler supports the C++11 feature, you can do it like this:

a::a() :arr({'a','b','c'}) {} 

Otherwise, you'll have to do it manually, or you can use a function like memcpy:

a::a() { memcpy(arr,"abc",3); // The other initialization method will fill the rest in with 0, // I don't know if that's important, but: std::fill(arr + 3, arr + 25, '\0'); } 

Or, as suggested by ephemient:

a::a() { strncpy(arr, "abc", 25); } 

If your compiler supports the C++11 feature, you can do it like this:

a::a() :arr({'a','b','c'}) {} 

Otherwise, you'll have to do it manually, or you can use a function like memcpy:

a::a() { memcpy(arr,"abc",3); // The other initialization method will fill the rest in with 0, // I don't know if that's important, but: std::fill(arr + 3, arr + 25, '\0'); } 

If your compiler supports the C++11 feature, you can do it like this:

a::a() :arr({'a','b','c'}) {} 

Otherwise, you'll have to do it manually, or you can use a function like memcpy:

a::a() { memcpy(arr,"abc",3); // The other initialization method will fill the rest in with 0, // I don't know if that's important, but: std::fill(arr + 3, arr + 25, '\0'); } 

Or, as suggested by ephemient:

a::a() { strncpy(arr, "abc", 25); } 
Source Link
Benjamin Lindley
  • 104.2k
  • 11
  • 210
  • 285

If your compiler supports the C++11 feature, you can do it like this:

a::a() :arr({'a','b','c'}) {} 

Otherwise, you'll have to do it manually, or you can use a function like memcpy:

a::a() { memcpy(arr,"abc",3); // The other initialization method will fill the rest in with 0, // I don't know if that's important, but: std::fill(arr + 3, arr + 25, '\0'); }