试图创建一个C ++二进制文件,该文件接收数据文件和约束文件并输出聚类结果

问题描述 投票:0回答:1

我已经从下面的代码开始了,但是不确定。目的是通过输入数据文件和约束文件来创建二进制文件,以输出聚类结果。任何人都可以帮助指导我吗?

#include <iostream>
#include "fstream"
using namespace std;

void file_to_binary(string file_name) {
ifstream file_to_open(file_name);
ofstream file_to_write("binary_file.bin", ios::binary);

float value;

if (file_to_open.is_open()) {
    while (!file_to_open.eof()) {
        file_to_open >> value;
        file_to_write.write((char*)&value, sizeof(float));
    }
  }
}

int main() {
    file_to_binary("iris.arff");
    return 0;
}

这只是输出二进制数据iris.arff。我也需要在此处输出约束文件,以便随后可以像下面一样运行代码。

运行集群的伪代码:

class COPKmeans {
    run_clustering(data, constraint) {
        call [binary file from above]
        load result
        return
}

有人可以帮忙吗?我是C ++的初学者,非常困惑。

c++ binary cluster-analysis fstream iostream
1个回答
0
投票
#include "fstream" // <fstream> would make more sense, but that's not the problem.

while (!file_to_open.eof()) { // Use "while (file_to_open >> value)"
    file_to_open >> value;    // to loop on valid input. Also not the problem.

不幸的是,该程序既不完整,也不简单。尝试仅打开一个二进制文件(验证它是否已打开)并向其中写入42。如果您无法完成这项工作,请完整发布该小程序。

© www.soinside.com 2019 - 2024. All rights reserved.