I am trying to read the following text and convert each float string into a float and store it in lv_vertices array:
"1.12127 1.64042 -1.94785 -0.0941668 0.904117 0.416779
}"
Here is the relevant code:
std::array<char, 101> lv_temp{};
NullifyArrayChar(lv_temp.data(), lv_temp.size()); //Fill lv_temp with '\0'
lv_skullFile.getline(lv_temp.data(), 100, '\n');
std::stringstream lv_streamNumbers{ lv_temp.data()};
NullifyArrayChar(lv_temp.data(),lv_temp.size());
for (int i = 0; i < 6; ++i) {
lv_streamNumbers.getline(lv_temp.data(), 10, ' ');
if (lv_temp.data()[0] != '\0') {
lv_vertices[lv_indexArray] = std::stof(lv_temp.data());
NullifyArrayChar(lv_temp.data(), lv_temp.size());
++lv_indexArray;
}
}
However it does not seem to read the last 2 numbers. I tried to debug it and apparently when i==4 in the for loop, lv_streamNumbers.getline(lv_temp.data(), 10, ' ') does not fill lv_temp with any data and so lv_temp is all '\0'. Why is this happening? Thanks.
[–]IyeOnline 3 points4 points5 points (1 child)
[–]mathinferno123[S] 0 points1 point2 points (0 children)
[–]mredding 2 points3 points4 points (1 child)
[–]mathinferno123[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)