vendredi 29 juillet 2016

failbit set when creating a file, when the file name is passed using composition syntax

I have the following function which creates files as expected when run on its own:

MatchedFilter::MatchedFilter(double * dataIn, int dataInSize, std::string name)
{
    fileNameOutput = name;

    fileNameOutput.insert((name.length() - 4),"OUTPUT");

    std::ofstream dataDump(fileNameOutput);

    std::ios_base::iostate errcheck = dataDump.rdstate();

    if((errcheck & std::fstream::failbit) != 0)
    {
      std::cout << "Failbit has occured" << std::endl;
    }else if((errcheck & std::fstream::badbit) != 0)
    {
      std::cout << "Badbit has occured" << std::endl;
    }else if((errcheck & std::fstream::eofbit) != 0)
    {
      std::cout << "EndofFile bit has occured" << std::endl;
    }  
}  

However when I create a MatchedFilter object inside a second class called DeModulator using composition, and pass a const string for the name variable the file fails to create, and I get a Failbit.

Here is the DeModulator class:

DeModulator::DeModulator(double * dataIn, int dataInSize) : 
filter2k(dataIn,dataInSize,"data/FilterKernal/2k.txt"), 
filter1k(dataIn,dataInSize,"data/FilterKernal/1k.txt")
{

}

What is wrong with passing a string const using this method, to create open a file?

Ubuntu G++ C++11

Aucun commentaire:

Enregistrer un commentaire