How to copy char *s to char array object in C++

1 Answer

0 votes
#include <iostream>
#include <cstring>
#include <array>

int main ()
{
  const char *s = "C++ Programming";

  std::array<char, 15> arr;

  std::memcpy(arr.data(), s, strlen(s) + 1);

  std::cout << arr.data();

  return 0;
}
 
 
 
/*
run:
 
C++ Programming
  
*/

 



answered Jul 28, 2020 by avibootz

Related questions

1 answer 269 views
2 answers 333 views
333 views asked Aug 15, 2022 by avibootz
1 answer 221 views
1 answer 259 views
1 answer 290 views
1 answer 253 views
...