关于在类头文件中包含fstream头文件的错误消息

时间:2019-06-04 16:30:51

标签: c++11 visual-c++ c++-cli

OS-> Windows 7 VS Studio 2017专业版 项目类型C ++ / CLI

问题:我有一个说输出数据的类。如果我在outputData.h中包含fstream,它将无法编译,但是如果我在output.cpp中包含,它将可以正常编译。 此外,仅当fstream在output.cpp中时,应用程序才编译。我还有另一个类,需要在其中添加fstream,但是将其添加到.h或.cpp文件中后,应用程序将无法编译。

下面是一长串错误

    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();
}

0 个答案:

没有答案