I have an issue with reading files. Someone please help me figure out why |
I checked out your code and built it, now what?
Is there a reason
STRING
is defined to be
char*
, rather than
std::string
?
I added warnings to the makefile and rebuilt, you have a lot of relevant warnings. You should look into that. Add these flags to your compile line:
-Wall -Wextra -g
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
15├>STRING getFileContents(const STRING filepath) {
16│ std::string line;
17│ std::string text;
18│ std::ifstream myfile (filepath);
19│
20│ if (myfile.is_open()) {
21│ while (std::getline(myfile, line)) {
22│ text += line + "\n";
23│ }
24│
25│ myfile.close();
26│ }
27│
28│ STRING c = const_cast<STRING>(text.c_str()); // convert std::string to char*
29│ return c;
| |
This is the first function I stepped into. Knowing that
STRING
is
char*
, the compiler's tried to warn you about line 28, and you shut it up with that cast. But now you're left to deal with the problem it warned you about.
I suggest you document your project aims, and what some code might look like. Then you'll be in a position to get some help. At the moment, there's nothing I can do beyond what I've said here.
Also, it might be best to move the topic to
General C++ Programming as this isn't Windows specific.