Reading data from file into an array

Hi I have compiled your code, with the .txt it runs well, without gives the strage numbers that you see. So probably you are opening a file that does not exists, or can not be red. This snippet checks if the file exists, raises an error if not, and uses a vector(more suitable in c++)

How does ifstream’s eof() work?

-1 is get‘s way of saying you’ve reached the end of file. Compare it using the std::char_traits<char>::eof() (or std::istream::traits_type::eof()) – avoid -1, it’s a magic number. (Although the other one is a bit verbose – you can always just call istream::eof) The EOF flag is only set once a read tries to read past the end of the file. If I …

Read more

Reading from file in c++ ifstream

What the inFile >> S does is take in the file stream, which is the data in you file, and uses a space delimiter (breaks it up by whitespace) and puts the contents in the variable S. For example: If we had a file that had the follow contents and we used inFile >> S with our file: we …

Read more