Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
std::string s("121 151 225 456");
std::stringstream ss(s);
T val;
do { ss >> val; cout << val << endl; } while( ss.good() ); 

 

Check if directory exists

Code Block
#include <sys/stat.h>

  bool dir_exists(const std::string& dir)
  {
    struct stat st;
    if( (stat(dir.c_str(),&st) == 0) && (((st.st_mode) & S_IFMT) == S_IFDIR) ) return true;
    return false;
  }

 

Check if file exists

Code Block
#include <fstream>  // for ifstream

  std::ifstream f("file.txt");
  if(not f.good()) ...

...