I am writing a program in C++ in which I need the comparsion of ofstream object with a double/int variable but the compiler gives me error that 'No operator == matches these operands, operands types are double == std::ofstream' my code is this.
void assign_clusters(double clusters_assigned[N], double X[N][M])
{
ofstream output[K]; //Creating array of K number of output file streams
for (int i = 0; i < K; i++)
{ //open all file streams
output[i].open(name + char('1' + i) + ".dat");
}
for (int i = 0; i < N; i++)
{
clusters_assigned[i] = find_max(Uik[i]);
if (clusters_assigned[i] == output[i])
The compiler gives error in this last line i.e. if statement and both contains values that are similar i.e. 1,1 or 2,2 etc for different iteration. Please guide me what should I do with this.
What is it that you are trying to do with the if statement if (clusters_assigned[i] == output[i])?
Are you trying to check if the stream output[i] contains the value clusters_assigned[i]?
Actually output[i] is an array of ofstream type which contains upto 6 number of items with and every time it contain values with in the range of 1 to K (2 or 3 or 4 or 5 or 6 or 7 etc i.e. only one value) and double type i.e. clusters_assigned[i] also contains that so I want to compare these because I am writting a program for Fuzzy K Means in which I should write every data item on their respective cluster (on file i.e. on hard disk) this type of comparison is necessary for this program. Any kind of type_casting etc will not work to achieve this goal.?
My goal is to write like this one...
if clusters_assigned[i] & output[i] == 1 so output[0] << cluster[0]; on file or if both are equal to 2 so it would write like output[1] << cluster[1] and so on.
Thanks for your reply but actually output_vector[i] is for creating K number of files on hard disk simple array will not fulfill my requirement. For example if K = 5 so, my progrom is going to write 5 files with the name of Cluster1.dat, Cluster2.dat......... Cluster5.dat but I am facing the problem of writing every data points on differenct cluster i.e. to cluster1 file, cluster2 etc.
My progrom works fine with simple cout statement the code of which is :
for (int i = 0; i < N; i++)
{
clusters_assigned[i] = find_max(Uik[i]);
cout << X[i][0] << " , " << X[i][1] << " belongs to Cluster # " << clusters_assigned[i] << endl;
}