fork download
  1. #include <vcclr.h>
  2. #include <vector>
  3. #include <memory>
  4.  
  5. struct char_pp{
  6. static std::auto_ptr<char> cstr(System::String^ s){
  7. pin_ptr<const wchar_t> wch = PtrToStringChars(s);
  8. size_t convertedChars = 0;
  9. size_t sizeInBytes = ((s->Length + 1) * 2);
  10. std::auto_ptr<char> ch(new char[sizeInBytes]);
  11. errno_t err = wcstombs_s(&convertedChars, ch.get(), sizeInBytes, wch, sizeInBytes);
  12. return ch;
  13. }
  14. std::vector<char*> v;
  15. char_pp(array<System::String^>^ s){
  16. v.reserve(s->Length);
  17. for each(System::String^ s in s){ v.push_back(cstr(s).release()); }
  18. }
  19. ~char_pp(){
  20. for(std::vector<char*>::iterator it=v.begin();it!=v.end();it++){ delete *it; }
  21. }
  22. char** get(){return &v[0];}
  23. };
  24.  
  25. void f(char* hogehoge[]){
  26. for(char** it=hogehoge;*it!=NULL;it++){
  27. printf_s("%s\n", *it);
  28. }
  29. }
  30.  
  31. int main(array<System::String^>^ args){
  32. cli::array<System::String^> ^hoge = gcnew cli::array<System::String^>{L"a", L"b", L"c"};
  33. char_pp p(hoge);
  34. p.v.push_back(NULL); //NULL終端配列が必要な場合
  35. f(p.get());
  36. return 0;
  37. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty