“Incomplete type not allowed ” when creating std::ofstream objects

As @Mgetz says, you probably forgot to #include <fstream>. The reason you didn’t get a not declared error and instead this incomplete type not allowed error has to do with what happens when there is a type that has been “forward declared”, but not yet fully defined. Look at this example: Notice we could not actually instantiate a Foo object or … Read more

Invalid conversion from ‘char’ to ‘const char *’

You’re trying to pass a char to LoadFileToString which takes in a char*. I think what you intend to do is this Notice that I’m reading the input into a string instead of a char since the LoadFileToString expects a (C-style) string to be passed in; instead you’re reading and trying to pass a character … Read more

Reading from text file until EOF repeats last line

Just follow closely the chain of events. Grab 10 Grab 20 Grab 30 Grab EOF Look at the second-to-last iteration. You grabbed 30, then carried on to check for EOF. You haven’t reached EOF because the EOF mark hasn’t been read yet (“binarically” speaking, its conceptual location is just after the 30 line). Therefore you … Read more

Using the fstream getline() function inside a class

the function for streams that deals with std::string is not a member function of istream but rather a free function it is used like so. (the member function version deals with char*). It is worth noting there are better safer ways to do what you are trying to do like so: don’t reinvent the wheel; … Read more

How to read a file line by line or a whole text file at once?

ou can use std::getline : Also note that it’s better you just construct the file stream with the file names in it’s constructor rather than explicitly opening (same goes for closing, just let the destructor do the work). Further documentation about std::string::getline() can be read at CPP Reference. Probably the easiest way to read a whole text file is just … Read more