Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. int main(int argc, char* argv[])
  2. {
  3. path p (argv[1]); // p reads clearer than argv[1] in the following code
  4.  
  5. try
  6. {
  7. if (exists(p)) // does p actually exist?
  8. {
  9. if (is_regular_file(p)) // is p a regular file?
  10. cout << p << " size is " << file_size(p) << 'n';
  11.  
  12. else if (is_directory(p)) // is p a directory?
  13. {
  14. cout << p << " is a directory containing:n";
  15.  
  16. typedef vector<path> vec; // store paths,
  17. vec v; // so we can sort them later
  18.  
  19. copy(directory_iterator(p), directory_iterator(), back_inserter(v));
  20.  
  21. sort(v.begin(), v.end()); // sort, since directory iteration
  22. // is not ordered on some file systems
  23.  
  24. for (vec::const_iterator it (v.begin()); it != v.end(); ++it)
  25. {
  26. cout << " " << *it << 'n';
  27. /****************** stuck here **************************/
  28. // I need to cast *it to a const char* filename
  29. /****************** stuck here **************************/
  30. }
  31. }
  32.  
  33. else
  34. cout << p << " exists, but is neither a regular file nor a directoryn";
  35. }
  36. else
  37. cout << p << " does not existn";
  38. }
  39.  
  40. catch (const filesystem_error& ex)
  41. {
  42. cout << ex.what() << 'n';
  43. }
  44.  
  45. return 0;
  46. }
  47.  
  48. const std::string & s = (*it).string();
  49. const char *str = s.c_str(); //this is what you want
  50.  
  51. const std::string & string() const;
  52. std::string native_file_string() const;
  53. std::string native_directory_string() const;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement