fork download
  1. #include <iostream>
  2. #include <cassert>
  3. using std::string;
  4. using std::cout;
  5. using std::endl;
  6.  
  7. int main(int argc,char* argv[])
  8. {
  9. assert(argc>0);
  10. static constexpr char levels_dir[]="levels";
  11. static constexpr char slashes[]="/\\";
  12.  
  13. const string bin_path(argv[0]);
  14. const auto slash_position = bin_path.find_last_of(slashes);
  15. assert(slash_position!=string::npos);
  16. const auto levels_path = bin_path.substr(0,slash_position+1)
  17. + levels_dir
  18. + bin_path[slash_position];
  19.  
  20. cout << "Bin path: " << bin_path << endl
  21. << "Levels_path: " << levels_path << endl;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Bin path: ./prog
Levels_path: ./levels/