How I can make file multiple of `segmentSize` I multiply the original file and cut a piece of final file with intention to do it a multiple of segmentSize times with minimum loss of data.

Example: I have a file size of 4 bits, and segment size of 3 bits;
I do extend my original in 3 times or 6 and so far and so forth.

or another example:
I have file size of 48 000 000 and segment (1024*1024*6*2)
and if I multiply the original file by 5 (make file that was contain 5 original files in row) (48 000 000 * 5)/(1024*1024*6*2) = 19.0734...1 -- I will have only 0.7% loss.
And then I make my extended file (five times of original) by copying original file into Temp.iqbin 5 times, and after read the segment (1024*1024*6*2) from Temp.iqbin and write it into my final.iqbin (I do this 19 times in the last cycle) and I get Final file that is multiple of segmentSize (because I trimmed some data by not copying it from Temp.iqbin size).

    double criteria = 0;
    int arraySize = 0;

    double box = 1;
    int box_i = 0;
    double coeff;
    int sizeFactor;
    if (size &lt; 1300000)
        sizeFactor = 8;
    else
        sizeFactor = 2;

    //if original file too big, reduce the extend coeff
    if (size &lt; segmentSize) {
        coeff = segmentSize / size;
        coeff = (int)coeff;
    }
    else
        coeff = 0;

    //optimization by criteria of minimum data loss in final file
    for (int i = 1; i &lt; 4*sizeFactor; i++) {
        criteria = (size*(i+coeff)) / segmentSize;
        criteria = criteria - int(criteria);
        box = box &lt; criteria ? box : criteria;
        box_i = box &lt; criteria ? box_i : i+coeff;
    }

    std::vector&lt;char&gt; vector(segmentSize);

    //Remove old Temp file
    std::remove("Temp.iqbin");
    std::fstream ofs1("Temp.iqbin", std::ios::binary | std::ios::out | std::ios::app | std::ios::in);
    fs.seekg(0, std::ios::beg);

    //i do the file that is multiple of original file in box_i (the size
    //which guarantee minimum data loss after trim) times
    for (int i = 0; i &lt; box_i; i++) {
        ofs1 &lt;&lt; fs.rdbuf();
        fs.seekg(0, std::ios::beg);
    }

    //back to beginning of file
    ofs1.seekg(0, std::ios::beg);
    //remove old final.iqbin
    std::remove("final.iqbin");
    std::ofstream ofs("final.iqbin", std::ios::binary | std::ios::out |std::ios::app);
    //Write Segments one by one to final.iqbin file
    //i read segments(have size i want new file was multiple of) and write
    //it to the newfile
    coeff = ((size*box_i) / segmentSize);
    for (int i = 0; i &lt; (int)coeff; i++) {
        //Read Segment from Temp file
        ofs1.read(&amp;vector[0], segmentSize);
        //Write Segment to final.iqbin file
        ofs.write(&amp;vector[0], segmentSize);
    }
    ofs1.close();
    //remove Temp file
    std::remove("Temp.iqbin");


This code is working and it even works fast for files that I feed to it, but I think it's not the optimal solution.
As far as I can understand (or better say: guess) what you mean, the optimum solution is a file size equal to the least common multiple of the given data size and the segment size: multiply your file N times:

\$ N = {segmentSize} / \operatorname{gcd}({dataSize}, \ {segmentSize}) \$

so you get a file of size

\$S = \operatorname{lcm}({dataSize}, \ {segmentSize})\$

which is \$M\$ full segments:

\$M = {dataSize} / \operatorname{gcd}({dataSize}, \ {segmentSize}) \$

For data size 48 million and segment size 12 Meg the greatest common divisor is 3,072 = 3*1024, so their least common multiple is:
\$196,608,000,000 = 2^{12} \times datasize = 5^6 \times segmentsize.\$