因此,给出了答案。很好,正确。已接受并接受。很好。
仅作为附加信息,我将展示使用更现代的语言元素的C ++解决方案。该解决方案跳过了中间文件(可以由一个文件名生成),也不需要使用“ X”(也可以非常简单地添加)。
使用STL,我们可以用净的5行代码提供从原始源文件到最终目标文件的解决方案。
请参阅:#include
#include
#include
#include
#include
#include
#include
std::regex reFloat{ R"([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)" };
using SVector = std::vector<:string>;
using SVectorIter = SVector::iterator;
int main() {
// Open source file and check, if it coud be opened
if (std::ifstream sourceFileStream{ "r:\\dummyValues.dat" }; sourceFileStream) {
// Open destination file and check, if it could be opened
if (std::ofstream finalFileStream("r:\\benchmarks_final.dat"); finalFileStream) {
// Algorithm start ----------------------------------------------------------
// Define a string variable and initialize it with the contents of the file
std::string completeFile(std::istreambuf_iterator(sourceFileStream), {});
// Define vector and initialize it with all float values from the file
SVector values(std::sregex_token_iterator(completeFile.begin(), completeFile.end(), reFloat), {});
// Iterate over the vector and find the next value equal to first-value
for (SVectorIter svi{ values.begin() }; (svi = std::find(svi, values.end(), values[0])) != values.end(); ++svi) {
// Copy 16 value to the final file
std::copy_n(svi, std::min(16, std::distance(svi, values.end())), std::ostream_iterator<:string>(finalFileStream, " "));
finalFileStream << '\n';
}
// Algorithm end ----------------------------------------------------------
}
else {
std::cerr << "\n*** Error: Could not open final file\n";
}
}
else {
std::cerr << "\n*** Error: Could not open source file\n";
}
}
我想不是,但是如果您有兴趣了解这一点,那么我会向您解释。请问,我很乐意提供帮助-