我正在阅读文本文件中的列表,时间格式如下
1 00:03.56
2 00:06.12
我需要接受其他每一行,并对此进行一些分析,但是,当我读入它并尝试使用" std :: stof()"将此转换为可用形式的功能,它在第一次转换时挂起(在4核i7上的单核上10分钟以上)。附上相关代码。
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++;
}
这编译很好,大多数子循环都是为了使编译正确。如果重要的话,我在Windows 10上使用Visual Studio 15.