what different between #include <fstream.h> and no h

// Why some iostream need put .h and other no need put .h ????

//It prints a line of text

#include <iostream>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::ios;
#include <fstream>
using std::ofstream;
#include <math.h>
#include <iomanip>
using namespace std;

#include <conio.h>

#define LAJUR 6
#define BARIS 1036

void data();
int count=0, number,i,j;
char k;
double newcase[LAJUR];
double localsim[BARIS][LAJUR];

int oldCases[BARIS][LAJUR+1];

fstream infile;
fstream outfile;

int main(){
data();
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Car Classify System *";
cout << "\n* *";
cout << "\n*************************************";
cout << "\n\n";
//INPUT NEW CASE

cout << "\n\n1st data : Buying --> v-high[1], high[2], med[3], low[4]\n"
<< "2nd data : Maint --> v-high[1], high[2], med[3], low[4]\n"
<< "3rd data : Doors --> 2,3,4,5-more [5]\n"
<< "4th data : Person --> 2,4,more [5]\n"
<< "5th data : Lug_boot --> big[1], med[2], small[3]\n"
<< "6th data : Safety --> high[1], med[2], low[3]\n\n";
for(i=0;i<LAJUR;i++){
cout << "Insert data " <<i+1 <<":\n";
cin >> newcase[i];
}
cout << "New Case: {";
for(i=0;i<LAJUR;i++){
cout << newcase[i] <<",";
}
cout << "}\n\n";

//CALCULATE WEIGHT

int weight[LAJUR]={1,1,1,1,1,1};
int sumweight=0;
double normWeight[LAJUR]={0,0,0,0,0,0};

for(i=0;i<LAJUR;i++){
sumweight= sumweight + weight[i];
}
cout << "sumweight: " << sumweight << "\n";
for(i=0;i<LAJUR;i++){
normWeight[i] = double(weight[i])/double(sumweight);
}

//CALCULATE LOCAL SIMILARITY

for(i=0;i<BARIS;i++){
for(j=1;j<LAJUR+1;j++)
{
if(newcase[j-1]==oldCases[i][j]){
localsim[i][j]=1;
}
else{
localsim[i][j]=0;
}
}
}
//CALCULATE GLOBAL SIMILARITY
double globalsim[BARIS]={0,0,0,0,0,0};
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Global Similarity *";
cout << "\n***************************************";
cout << "\n\nGlobal Similarity " << "Class\n";

for (i=0;i<BARIS;i++){
for(j=0;j<LAJUR;j++){
globalsim[i] = (globalsim[i] + localsim[i][j+1]*normWeight[j]);
}
globalsim[i]= globalsim[i]*100;
cout << "\n";
cout << globalsim[i] << "% "<< oldCases[i][0];
}
for(i=0;i<10;i++){
cout << "\n";
cout << globalsim[i] << "% " << oldCases[i][0];
}

//SORT SIMILARITY RESULT
double temp;
double tempClass[BARIS];
for(i=0;i<BARIS;i++){
tempClass[i]=oldCases[i][0];
}
for(i=0;i<BARIS;i++){
for(j=0;j<BARIS;j++){
if(globalsim[j]<globalsim[j+1]){
temp=globalsim[j];
globalsim[j]=globalsim[j+1];
globalsim[j+1]=temp;

temp=tempClass[j];
tempClass[j]=tempClass[j+1];
tempClass[j+1]=temp;
}
else{
}
}
}
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Sorted Similarity Result *";
cout << "\n* *";
cout << "\n*************************************";
cout << "\n\nGlobal Similarity (Sort) "<<"Class\n\n";

for(i=0;i<10;i++){
cout << globalsim[i] << "% " << tempClass[i] <<"\n";
}
//MAJORITY VOTING
int class1 =0,class2=0,class3=0,class4=0;
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Majority Voting *";
cout << "\n* *";
cout << "\n*************************************";
cout << "\n\nGlobal Similarity "<<" Class\n\n";
for(i=0;i<10;i++){
if(globalsim[i] > 80.00)
{
cout << globalsim[i] << "% " << tempClass[i] << "\n";
{ if(tempClass[i]==1)
class1=class1+1;
else if (tempClass[i]==2)
class2=class2+1;
else if (tempClass[i]==3)
class3=class3+1;
else if (tempClass[i]==4)
class4=class4+1;
}
}
}
int tempValue;
int array[4];
array[0]=class1;
array[1]=class2;
array[2]=class3;
array[3]=class4;

for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(array[i] <= array[j])
{
tempValue=array[i];
array[i]=array[j];
array[j]=tempValue;
}
}
}
//PRINT RESULT
cout << "\n\n";
cout<<"Class 1 ="<< class1<<endl;
cout<<"Class 2 ="<< class2<<endl;
cout<<"Class 3 ="<< class3<<endl;
cout<<"Class 4 ="<< class4<<endl;

cout << "\nThe class for the new case is ";
if(array[3]==class1)
cout << "v-good"<<endl;
else if(array[3]==class2)
cout << "good"<<endl;
else if(array[3]==class3)
cout << "acc"<<endl;
else if(array[3]==class4)
cout << "unacc"<<endl;
else {
cout << " Sorry, system cannot define the car's class!";

}
cout << "\n\n";
}
void data()
{
infile.open("car.txt",ios::in);

cout<<"No Class Buying Maint Doors Persons "
<<"Lug_boot Safety\n\n";
for(i=0;i<BARIS;i++){
infile>>oldCases[i][0];
infile>>oldCases[i][1];
infile>>oldCases[i][2];
infile>>oldCases[i][3];
infile>>oldCases[i][4];
infile>>oldCases[i][5];
infile>>oldCases[i][6];
}
//Knowledge base output
for(i=0;i<10;i++)
{ number=i+1;
cout<<setw(4)<<setiosflags(ios::left)<<number
<<oldCases[i][0]<<" "
<<oldCases[i][1]<<" "
<<oldCases[i][2]<<" "
<<oldCases[i][3]<<" "
<<oldCases[i][4]<<" "
<<oldCases[i][5]<<" "
<<oldCases[i][6]<<endl;
}
//cout<<"Count = "<<count;
}





Did you really need to post your entire program to ask that question? =P

Anyway, you #include whatever filename the file has. The reason it's <iostream> and not <iostream.h> is because the file name is iostream. There's no .h on it. For whatever reason, the C++ standard lib headers have no extention.

As for <math.h>... that's a standard C (read: not C++) header. C headers had the .h.

C++ "adopted" some of the old C headers, but renamed them. They got rid of the .h at the end and prefixed it with a c. So instead of #include <math.h>, you would include <cmath>

<math.h> still works though because most /all C++ compilers are also C compilers and therefore come with both the C and C++ standard libraries.
When C++ was first created, all of the files in the standard runtime library ended in .h. Life was consistent, and it was good. The original version of cout and cin lived in iostream.h. When the language was standardized by the ANSI committee, they decided to move all of the functions in the runtime library into the std namespace (which is generally a good idea). However, this presented a problem: if they moved all the functions into the std namespace, none of the old programs would work any more!

To try to get around this issue and provide backwards compatibility for older programs, a new set of header files was introduced that use the same names but lack the .h extension. These new header files have all their functionality inside the std namespace. This way, older programs that include #include <iosteam.h> do not need to be rewritten, and newer programs can #include <iostream>.

Make sure when you include a header file from the standard library that you use the non .h version if it exists. Otherwise you will be using a deprecated version of the header that is no longer supported.
Now i got it, Thank you so much for explain to me. ^.^V
Topic archived. No new replies allowed.