Search code examples
c++multidimensional-arrayfstreamexport-to-csv

Decreasing output fstream


I'm working with an pressure sensitive LED floor, which outputs its sensors in a 2D array. I want to record this data and send it to a CSV file. However with my current code I gather 300.000 KB per second.

void DemoProjectApp::recorddata()
{
    std::ofstream myfile;
    myfile.open("datafloor.csv");
    while(pressed = true)
    {

        for (int i = 0; i < ProjectSettings::NR_OF_TILES; i++)
        {
            myfile << "Tile" << i << ",";
            myfile << tileIndexToSensorValues[i][0] << ",";
            myfile << tileIndexToSensorValues[i][1] << ",";
            myfile << tileIndexToSensorValues[i][2] << ",";
            myfile << tileIndexToSensorValues[i][3] << "\n";
            myfile.flush();
        }

    }
    if(pressed = false)
    {
        myfile.close();
    }
}

Pressed is a boolean changing true or false to start and stop recording. Does anyone have a solution to decrease the output, but still get the relevant data?

Thanks in advance!


Solution

  • Okay, feeling really stupid but the answer was adding == at the pressed booleans. Totally overlooked it.