File.cpp 566 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "File.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <sstream>
  5. File::File(string path)
  6. {
  7. this->path = path;
  8. }
  9. File::File(const File& orig)
  10. {
  11. }
  12. File::~File()
  13. {
  14. }
  15. bool File::exists()
  16. {
  17. ifstream fileStream(path);
  18. return fileStream.good();
  19. }
  20. string File::read()
  21. {
  22. ifstream fileStream(path);
  23. if(!fileStream.good())
  24. {
  25. return "";
  26. }
  27. stringstream stream;
  28. string s;
  29. while(!fileStream.eof())
  30. {
  31. getline(fileStream, s);
  32. stream << s;
  33. stream << '\n';
  34. }
  35. return stream.str();
  36. }