dimanche 17 décembre 2017

stof hangs on runtime

I am reading in times from a list in a text file, with format in the following manner

1      00:03.56
2      00:06.12

I need to take in every other line, and do some analysis on this, but, when I read it in and try to use the "std::stof()" function to convert this to a usable form, it hangs on the very first conversion (10+ minutes at a single core on a 4 core i7). The relevant code is attached.

while (tf.is_open()) {
i++;
//std::cout << i << std::endl;
std::getline(tf, full);
std::stringstream tbreak;
tbreak.str(full);
int k = 0;
std::string milsec;
while (std::getline(tbreak, time, ' '))
{
//  std::cout << k << std::endl;
    if (k % 2 == 0) {
        k++;
        continue;
    }
    std::stringstream hrminsec;
    hrminsec.str(time);

    int m = 0;
    while (std::getline(hrminsec, brokentime, ':'))
    {
        //std::cout << brokentime << std::endl;

        if (m % 2 == 0)
        {
            m++;
            continue;
        }
        //if (m % 2 == 1) time = brokentime;
        //if (m % 3 == 2) milsec =brokentime;
        if (brokentime == "time" || brokentime == "times")
        {
            m++;
            continue;
        }
        //std::cout << brokentime << std::endl;
        std::stringstream further;
        int n = 0;
        further.str(brokentime);
        std::string temp;
        while (std::getline(further, temp, '.'))
        {
            //std::cout << temp << std::endl;
            if (n % 2 == 0) time = temp;
            time.erase(0, time.find_first_not_of('0'));
            //std::cout<<time <<std::endl;
            if (n % 2 == 1)milsec = temp;
            n++;
            if (i % 2 == 0) {
                float temp1 = std::stof(time);
                std::cout << temp1 << std::endl;
                float temp2 = std::stof(milsec);
                temp1 = temp1 + 0.01*temp2;
                int j = i - 2;
                t[j] = temp1;
                std::cout << j << std::endl;
            }
        }


        m++;
    }
    k++;
}

This compiles fine, and most of the sub loops were to get the compilation correct. I am using Visual Studio 15 on Windows 10 if that matters.

Aucun commentaire:

Enregistrer un commentaire