Davlog
Davlog

Reputation: 2238

C++ errors when using ios_base and ofstream

void DataSaver::save( const std::vector<long>& vec )
{
    using std::ios_base;
    std::ofstream file;
    file.open( "/home/david/Desktop/test", ios_base::out | ios_base::binary );
    for(int i = 0; i < vec.size(); i++)
        file << vec.at( i ) << "\00\01\10\00";
    file.close();
}

This causes a few errors :

g++ main.cpp datasaver.cpp
datasaver.cpp: In member function ‘void DataSaver::save(const std::vector&)’:
datasaver.cpp:11:16: error: aggregate ‘std::ofstream file’ has incomplete type and cannot be defined
datasaver.cpp:12:41: error: incomplete type ‘std::ios_base’ used in nested name specifier
datasaver.cpp:12:57: error: incomplete type ‘std::ios_base’ used in nested name specifier

I included iostream , ofstream and vector

Can someone explain whats wrong?

Upvotes: 1

Views: 1965

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172428

You probably need

#include <fstream>

as file streams are actually defined in it

Upvotes: 5

Related Questions