C++ ifstream failbit and badbit

According to cplusplus.com: failbit is generally set by an input operation when the error was related to the internal logic of the operation itself, so other operations on the stream may be possible. While badbit is generally set when the error involves the loss of integrity of the stream, which is likely to persist even … Read more

Fast textfile reading in c++

Updates: Be sure to check the (surprising) updates below the initial answer Memory mapped files have served me well1: #include <boost/iostreams/device/mapped_file.hpp> // for mmap #include <algorithm> // for std::find #include <iostream> // for std::cout #include <cstring> int main() { boost::iostreams::mapped_file mmap(“input.txt”, boost::iostreams::mapped_file::readonly); auto f = mmap.const_data(); auto l = f + mmap.size(); uintmax_t m_numLines = … Read more

Getting std :: ifstream to handle LF, CR, and CRLF?

As Neil pointed out, “the C++ runtime should deal correctly with whatever the line ending convention is for your particular platform.” However, people do move text files between different platforms, so that is not good enough. Here is a function that handles all three line endings (“\r”, “\n” and “\r\n”): std::istream& safeGetline(std::istream& is, std::string& t) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)