C++ Can';t输出到文本文件,文件为空

C++ Can';t输出到文本文件,文件为空,c++,file,text,output,ofstream,C++,File,Text,Output,Ofstream,我试图将一组变量输出到一个以制表符分隔的文本文件中,但一旦程序完成,结果文件将完全为空 string outFileName = "/Users/hbll-diteam/Desktop/" + identifier + ".csv"; ofstream out(outFileName.c_str()); out.open(outFileName); if(out.is_open()) { //cout <

我试图将一组变量输出到一个以制表符分隔的文本文件中,但一旦程序完成,结果文件将完全为空

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();
        }
string outFileName=“/Users/hbll-diteam/Desktop/”+标识符+“.csv”;
流出流(outFileName.c_str());
out.open(outFileName);
if(out.is_open())
{

//cout打开文件两次,第二次失败,但没有检查失败

ofstream out(outFileName.c_str());
打开文件

out.open(outFileName);

尝试打开文件失败,导致流处于错误状态。
是否打开
可能不会检查错误状态。

当您在调试器中运行它(或添加打印)时,它是否会告诉您文件是否打开?是的,文件已打开(使用注释掉的cout语句检查)工作正常!谢谢。