CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FileIO.cc
Go to the documentation of this file.
1 /*
2  * FileIO.cc
3  *
4  * Created on: Sep 25, 2012
5  * Author: aspataru
6  */
7 
8 #include "../interface/FileIO.h"
9 
10 #include <iostream>
11 #include <fstream>
12 #include <streambuf>
13 #include <cstdlib>
14 #include <dirent.h>
15 #include <stdio.h>
16 #include <sys/stat.h>
17 #include <cstring>
18 
19 using namespace jsoncollector;
20 using std::string;
21 using std::ofstream;
22 using std::vector;
23 using std::ifstream;
24 using std::strlen;
25 
26 void FileIO::writeStringToFile(string& filename, string& content) {
27  ofstream outputFile;
28  outputFile.open(filename.c_str());
29  outputFile << content;
30  outputFile.close();
31 }
32 
34  if (!fileExists(filename))
35  return false;
36 
37  std::ifstream inputFile(filename.c_str());
38 
39  inputFile.seekg(0, std::ios::end);
40  content.reserve(inputFile.tellg());
41  inputFile.seekg(0, std::ios::beg);
42 
43  content.assign((std::istreambuf_iterator<char>(inputFile)),
44  std::istreambuf_iterator<char>());
45 
46  inputFile.close();
47  return true;
48 }
49 
50 bool FileIO::fileExists(string& path) {
51  ifstream ifile(path.c_str());
52  return ifile;
53 }
static bool fileExists(std::string &path)
Definition: FileIO.cc:50
static bool readStringFromFile(std::string &filename, std::string &content)
Definition: FileIO.cc:33
static void writeStringToFile(std::string &filename, std::string &content)
Definition: FileIO.cc:26
#define end
Definition: vmac.h:37
tuple filename
Definition: lut2db_cfg.py:20