C++写数据到文件里,但是文件没有内容怎么处理

自己传的引用参数,是空的不知道怎么调用修改后的参数值,导致内容无法写到文件中

光凭叙述也不知道你具体遇到了什么问题,把源码贴上来吧



#include <fstream>
#include<iostream>
#include <vector>
#include <stdio.h>
using namespace std;



//int* pInt;
typedef struct uSeg
{
    int test_ID;
    int gates;
    int depth;
    int Aid;
    // int height;
    int amplitude;
    int threshold;
}USeg;

USeg b;
vector<USeg> m_bData;
void run1(vector<USeg> &m_bData) {


    std::ofstream fout;

    

        for (int j = 0; j <10; j++) {
            
                b.Aid =j, b.amplitude = j + 1, b.depth = j + 2, b.depth = j + 3, b.gates = j + 4, b.test_ID = j + 5, b.threshold = j + 6;
            /*j->Aid; */ 
            /*( j + 1)->amplitude,  (j + 2)->depth, (j + 4)->gates ,   (j + 5)->test_ID,  (j + 6)->threshold;*/
            m_bData.push_back(b);
        }
        
        for (vector<USeg>::iterator j=m_bData.begin();j!=m_bData.end();j++)
        {
        fout <<j->test_ID << ", " << j->gates << ", " << j->depth << "," << j->Aid << "\n";        
        }
    
        
            /*    b.Aid =j;
                b.amplitude =i + 1;
                b.depth = j +1 ;
                b.gates = j + 3;
                b.test_ID = j + 4;
                b.threshold = j + 5;*/
            
    
        fout.close();


    
}

void run( vector<USeg> &m_bData,string filepath ) {
    //vector<USeg> m_bData;
    std::ofstream fout;
    //fout = std::ofstream("test.txt");
    fout = std::ofstream(filepath);
    run1(m_bData);
    //USeg b = { 1,2,3,4,5,6 };
    //fout << std::fixed;   //设置浮点型
    //fout.precision(2);    //精度为2
    
    //for (size_t i = 0; i < m_bData.size(); i++)
    //{
    //    for (int j = 0; j < 5; j++)
    //    /*    b.Aid =j;
    //        b.amplitude =i + 1;
    //        b.depth = j +1 ;
    //        b.gates = j + 3;
    //        b.test_ID = j + 4;
    //        b.threshold = j + 5;*/
    //        m_bData.push_back(j);
    //}

    /*if (fout.is_open())
    {

        vector<USeg>::iterator it;
        for (it = m_bData.begin(); it != m_bData.end(); it++)
        for(int i=0;i<m_bData.size();i++)
            fout << b.test_ID << ", " << b.gates << ", " << b.depth << "," << b.Aid << "\n";
        fout << b.test_ID << ", " << b.gates << ", " << b.depth << "," << b.Aid <<  "\n";
        fout << b.Aid << endl;    
        Map_UltraRcgSection::iterator beg = m_leftUltraRcgSct.begin();
        Map_UltraRcgSection::iterator end = m_leftUltraRcgSct.end();
        vector<int>::iterator it = m_bData.begin();
        vector<int>::iterator it = m_bData.end();
        for (; beg != end; beg++)
        {
            fout<<"0"<<
            UltrRcgSection tmp;
            USeg tmp;
            tmp = beg->second;
            int i = tmp.severity;
            if (i > 6)
                i = tmp.severity;
            fout << tmp.isTopRail << ", " << tmp.rec_code << ", " << tmp.avgTestId << ", " << tmp.endTestID - tmp.startTestID << ", " << tmp.min_depth << ", " << tmp.max_depth << ", " << i << "\n";
        }
        beg = m_rightUltraRcgSct.begin();
        end = m_rightUltraRcgSct.end();
        for (; beg != end; beg++)
        {
            //fout<<"0"<<
            USeg tmp;
            tmp = beg->second;
            int i = tmp.severity;
            if (i > 6)
                i = tmp.severity;
            fout << tmp.isTopRail << ", " << tmp.rec_code << ", " << tmp.avgTestId << ", " << tmp.endTestID - tmp.startTestID << ", " << tmp.min_depth << ", " << tmp.max_depth << "," << i << "\n";
        }
        fout.close();
    }*/
}

int main() {
    vector<USeg> m_bData;
    run(m_bData,"d://1.csv");
    return 0;
}