Cannot output to text file, file is empty

I am trying to output a bunch of variables to a tab delimited text file, but once the program is finished, the resulting file is completely empty.

string outFileName = "/Users/hbll-diteam/Desktop/" + identifier + ".csv";
        ofstream out(outFileName.c_str());
        out.open(outFileName);
        if(out.is_open())
        {
            //cout << ";eruigjnsldfijuglsidufblg yay";
            out << coCDM_LVL << '\t' << coCDM_LVLname << '\t' << creator << '\t' << contributors << '\t' << coTitle << '\t' << altTitle << '\t' << description << '\t' << dateOriginal << '\t' << dateSpan << '\t' << edition << '\t' << publisher << '\t' << physicalDescription << '\t' << scale << '\t' << extentField << '\t' << medium << '\t' << dimensions << '\t' << arrangement << '\t' << degree << '\t' << contributing << '\t' << names << '\t' << topics << '\t' << geoPlaceNames << '\t' << genre << '\t' << occupations << '\t' << functions << '\t' << subject << '\t' << langIN << '\t' << audience << '\t' << condition << '\t' << generalNotes << '\t' << collection << '\t' << linkToFindingAid << '\t' << source << '\t' << SIRSI << '\t' << callNumber << '\t' << coFullText << '\t' << COPYRIGHT << '\t' << rightsManagement << '\t' << rightsHolder << '\t' << contactAddress << '\t' << contactPhone << '\t' << contactEmail << '\t' << ACCESS_LEVEL << '\t' << PUBLISHER_DIGITAL << '\t' << refreshDate << '\t' << fileType << '\t' << format << '\t' << digitizationSpecs << '\t' << dateDigital << '\t' << height << '\t' << width << '\t' << checksum << '\t' << CHECKSUM << '\t' << colorSpace << '\t' << systemRequirements << '\t' << username << '\t' << metaEntryDate << '\t' << metaEntryTool << '\t' << identifier << '\t' << fileSize << '\t' << mediaType << '\t' << metaUser << '\t' << LIS_TAG << '\t' << identifier << endl;

            for(int i = 0; i < filenameList.size(); i++)
            {
                out << pgCDM_LVL << '\t' << pgCDM_LVLname << '\t' << '\t' << '\t' << "Page " << i + 1 << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t' << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t' << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t'  << '\t' << COPYRIGHT << '\t' << rightsManagement << '\t' << rightsHolder << '\t' << contactAddress << '\t' << contactPhone << '\t' << contactEmail << '\t' << ACCESS_LEVEL << '\t' << '\t' << '\t' << '\t' << format << '\t' << digitizationSpecs << '\t' << dateDigital << '\t' << '\t' << '\t' << '\t' << CHECKSUM << '\t' << '\t' << '\t' << '\t' << '\t' << '\t' << filenameList[i] << '\t' << '\t' << '\t' << '\t' << '\t' << filenameList[i] << endl;
            }
            out.close();
        }

      

+3


source to share


1 answer


You open the file twice, the second fails, but you don't validate it.

ofstream out(outFileName.c_str());

      

Opens a file



out.open(outFileName);

      

Attempting to open the file and fail, putting the stream in an error state. is_open

probably doesn't check for error status.

+6


source







All Articles