Skip to content

Std::fstream

File size check

ifstream file( "example.txt", ios::binary | ios::ate);
return file.tellg();

ofstream to vector

if (!file.eof() && !file.fail())
{
    file.seekg(0, std::ios_base::end);
    std::streampos fileSize = file.tellg();
    vec.resize(fileSize);

    file.seekg(0, std::ios_base::beg);
    file.read(&vec[0], fileSize);
}

Simple output file stream

std::vector<double> output;
// ...
std::fstream ofile("res/test/dwt_output1.txt", std::ios_base::out);
ofile.setf(std::ios_base::showpoint);
ofile.setf(std::ios_base::fixed, std::ios_base::floatfield);
for (int i = 0; i < output.size(); ++i) {
    ofile << output[i] << std::endl;
}

Favorite site