fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main() {
  7. string myArray[] = {"Apple", "Ball", "Cat"};
  8.  
  9. char test0[myArray[0].length()];
  10. strcpy(test0, myArray[0].c_str());
  11. char test1[myArray[1].length()];
  12. strcpy(test1, myArray[1].c_str());
  13. char test2[myArray[2].length()];
  14. strcpy(test2, myArray[2].c_str());
  15.  
  16. int i=0;
  17. for(i=0; i<(sizeof(test0)/sizeof(*test0)); i++)
  18. cout<<test0[i]<<" ";
  19. cout<<"\n";
  20. for(i=0; i<(sizeof(test1)/sizeof(*test1)); i++)
  21. cout<<test1[i]<<" ";
  22. cout<<"\n";
  23. for(i=0; i<(sizeof(test2)/sizeof(*test2)); i++)
  24. cout<<test2[i]<<" ";
  25. cout<<"\n";
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
A p p l e 
B a l l 
C a t