File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
includes/RhythmGameUtilities Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ #include < fstream>
4
+ #include < iostream>
5
+ #include < sstream>
6
+ #include < string>
7
+
8
+ namespace RhythmGameUtilities
9
+ {
10
+
11
+ std::string ReadFromFile (const char *path)
12
+ {
13
+ std::ifstream file (path);
14
+
15
+ if (!file)
16
+ {
17
+ std::cerr << " Failed to open " << path << " ." << std::endl;
18
+
19
+ return " " ;
20
+ }
21
+
22
+ return std::string ((std::istreambuf_iterator<char >(file)),
23
+ std::istreambuf_iterator<char >());
24
+ }
25
+
26
+ } // namespace RhythmGameUtilities
Original file line number Diff line number Diff line change
1
+ Hello, world!
Original file line number Diff line number Diff line change
1
+ #include < cassert>
2
+ #include < iostream>
3
+
4
+ #include " RhythmGameUtilities/File.hpp"
5
+
6
+ using namespace RhythmGameUtilities ;
7
+
8
+ void testReadFromFile ()
9
+ {
10
+ assert (ReadFromFile (" ./tests/Mocks/test.txt" ) == " Hello, world!\n " );
11
+
12
+ std::cout << " ." ;
13
+ }
14
+
15
+ int main ()
16
+ {
17
+ testReadFromFile ();
18
+
19
+ return 0 ;
20
+ }
You can’t perform that action at this time.
0 commit comments