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 194 views
2 answers 207 views
207 views asked Aug 15, 2022 by avibootz
1 answer 129 views
1 answer 178 views
1 answer 185 views
1 answer 158 views
...