mardi 4 juin 2019

error message on inclusion of fstream header file in class header

OS --> windows 7 VS studio 2017 professional Project type C++/CLI

Issue : I have a class say outputData . If I include fstream in outputData.h it fails to compile but if I include in output.cpp it compiles fine. Also application compiles only when fstream is in output.cpp. I have an another class where I need to add fstream but on adding it in either .h or .cpp file, the application fails to compile.

below is long list of error

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(293): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(295): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(329): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(331): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(351): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(353): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(293): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(747): note: see reference to class template instantiation 'std::basic_filebuf<_Elem,_Traits>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(294): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(328): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(330): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(350): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(352): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(890): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(892): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(909): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(911): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(948): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(950): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(890): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(962): note: see reference to class template instantiation 'std::basic_ifstream<_Elem,_Traits>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(891): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(908): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(910): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(948): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(949): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1105): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1107): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1124): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1126): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1163): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1165): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1105): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1177): note: see reference to class template instantiation 'std::basic_ofstream<_Elem,_Traits>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1106): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1123): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1125): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1163): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1164): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1325): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1327): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1344): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1346): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1383): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1385): warning C4003: not enough actual parameters for macro 'open'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1325): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1397): note: see reference to class template instantiation 'std::basic_fstream<_Elem,_Traits>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1326): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1343): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1345): error C2143: syntax error: missing ')' before '{'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1383): error C2059: syntax error: ')'
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.12.25827\include\fstream(1384): error C2143: syntax error: missing ')' before '{'
1>TestForm.cpp

outputData.h

//If i nclude header fstream here it  throws error
#pragma once
#include <string>
#include <vector>
//#include<fstream>


class OutputData
{
public:
    OutputData();
    OutputData(std::string fileToWriteIn, std::string headerNames, std::vector<std::string> data, int recordNumber);
    OutputData(std::string fileToWriteIn, std::vector<std::string> data, int recordNumber);
    ~OutputData();

    void addRecordsTofile();

private:
    std::string _fileName;
    std::string _headerName;
    std::vector< std::string > _dataVect;
    int _incrementingRecordNumber;

};

#include "OutputData.h"
#include <string>
#include <vector>
#include <fstream>
#include <iterator>

OutputData::OutputData()
{
}

OutputData::OutputData( std::string fileToWriteIn, std::string headerNames, std::vector<std::string>data, int recordNumber ) :
    _fileName( fileToWriteIn ), _headerName( headerNames ), _dataVect( data ), _incrementingRecordNumber( recordNumber )
{


}

OutputData::OutputData(std::string fileToWriteIn, std::vector<std::string> data, int recordNumber ):_fileName( fileToWriteIn ),
_dataVect( data ), _incrementingRecordNumber( recordNumber )
{
}

OutputData::~OutputData()
{

}

void OutputData::addRecordsTofile()
{
    std::ofstream outputFileHandler( _fileName );
    if (!outputFileHandler)
    {
        return;
    }
    if (outputFileHandler.is_open())
    {
        outputFileHandler << "Counter" << ",";
        outputFileHandler << _headerName << "\n";

        for (const auto &e : _dataVect)
        {
            outputFileHandler << ++_incrementingRecordNumber << ',' << e << "\n";
        }

    }
    outputFileHandler.close();
}

Aucun commentaire:

Enregistrer un commentaire