fork download
  1. //#include <iostream>
  2. //using namespace std;
  3.  
  4.  
  5. #include <vector>
  6. #include <string>
  7. #include <iterator>
  8.  
  9. std::vector<char *> fabricate(std::vector<std::string> const & v)
  10. {
  11. std::vector<char *> res(v.size() + 1, NULL);
  12. for (std::size_t i = 0; i != v.size(); ++i) { res[i] = v[i].c_str(); }
  13. return res;
  14. }
  15.  
  16. std::vector<std::string> const args_vector((std::istream_iterator<std::string>(std::cin)), std::istream_iterator<std::string>());
  17.  
  18. std::vector<char *> argv_vector = fabricate(args_vector);
  19.  
  20. int main(int argc, char * argv[])
  21. {
  22. argc = args_vector.size();
  23. argv = argv_vector.data();
  24.  
  25. // ...
  26. printf("argc %d\n",argc);
  27. printf("argv %s", argv);
  28.  
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
ashok baktha
compilation info
prog.cpp: In function ‘std::vector<char*, std::allocator<char*> > fabricate(const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’:
prog.cpp:12: error: invalid conversion from ‘const char*’ to ‘char*’
prog.cpp: At global scope:
prog.cpp:16: error: ‘cin’ is not a member of ‘std’
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:27: warning: format ‘%s’ expects type ‘char*’, but argument 2 has type ‘char**’
stdout

Standard output is empty