使用fstream.h,提示'fixed'‘showpoint’无明确定义;‘ios_base’is not a class or namspace name,该怎么解决
使用fstream.h,提示'fixed'‘showpoint’无明确定义;‘ios_base’is not a class or namspace name
#include "iostream.h"
#include "fstream.h"
#include "iomanip.h"
#include "stdio.h"
#include "stdlib.h"
int main()
{
char automobile[50];
int year;
double a_price;
double d_price;
ofstream outFile;
outFile.open("carinfo.txt");
cout<<"Enter the make and model of automobile: ";
cin.getline(automobile,50);
cout<<"Enter the model year: ";
cin>>year;
cout<<"Enter the original asking price: ";
cin>>a_price;
d_price=0.913*a_price;
cout<<fixed;
cout.precision(2);
cout.setf(ios_base::showpoint);
cout<<"Make and model: "<<automobile<<endl;
cout<<"Year: "<<year<<endl;
cout<<"Was asking $"<<a_price<<endl;
cout<<"Now asking $"<<d_price<<endl;
outFile<<fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
outFile<<"Make and model: "<<automobile<<endl;
outFile<<"Year: "<<year<<endl;
outFile<<"Was asking $"<<a_price<<endl;
outFile<<"Now asking $"<<d_price<<endl;
outFile.close();
return 0;
}
------解决方案--------------------
错得太离谱了也。 人家说的很清楚,fixed你没有定义首先,我也不知道ios_base是啥东西啊,好像你是想控制输出格式对吧那就就类似于.sef(ios::showbase||ios::showpoint),而你这个ios_base是啥呢?
那个fixed可能只有你知道。。我注释起来了:
int main()
{
char automobile[50];
int year;
double a_price;
double d_price;
ofstream outFile;
outFile.open("carinfo.txt");
cout<<"Enter the make and model of automobile: ";
cin.getline(automobile,50);
cout<<"Enter the model year: ";
cin>>year;
cout<<"Enter the original asking price: ";
cin>>a_price;
d_price=0.913*a_price;
//cout<<fixed;
cout.precision(2);
cout.setf(ios::showbase||ios::showpoint);
cout<<"Make and model: "<<automobile<<endl;
cout<<"Year: "<<year<<endl;
cout<<"Was asking $"<<a_price<<endl;
cout<<"Now asking $"<<d_price<<endl;
//outFile<<fixed;
outFile.precision(2);
outFile.setf(ios::showbase||ios::showpoint);
outFile<<"Make and model: "<<automobile<<endl;
outFile<<"Year: "<<year<<endl;
outFile<<"Was asking $"<<a_price<<endl;
outFile<<"Now asking $"<<d_price<<endl;
outFile.close();
return 0;
}
#include "iostream.h"
#include "fstream.h"
#include "iomanip.h"
#include "stdio.h"
#include "stdlib.h"
int main()
{
char automobile[50];
int year;
double a_price;
double d_price;
ofstream outFile;
outFile.open("carinfo.txt");
cout<<"Enter the make and model of automobile: ";
cin.getline(automobile,50);
cout<<"Enter the model year: ";
cin>>year;
cout<<"Enter the original asking price: ";
cin>>a_price;
d_price=0.913*a_price;
cout<<fixed;
cout.precision(2);
cout.setf(ios_base::showpoint);
cout<<"Make and model: "<<automobile<<endl;
cout<<"Year: "<<year<<endl;
cout<<"Was asking $"<<a_price<<endl;
cout<<"Now asking $"<<d_price<<endl;
outFile<<fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
outFile<<"Make and model: "<<automobile<<endl;
outFile<<"Year: "<<year<<endl;
outFile<<"Was asking $"<<a_price<<endl;
outFile<<"Now asking $"<<d_price<<endl;
outFile.close();
return 0;
}
------解决方案--------------------
错得太离谱了也。 人家说的很清楚,fixed你没有定义首先,我也不知道ios_base是啥东西啊,好像你是想控制输出格式对吧那就就类似于.sef(ios::showbase||ios::showpoint),而你这个ios_base是啥呢?
那个fixed可能只有你知道。。我注释起来了:
int main()
{
char automobile[50];
int year;
double a_price;
double d_price;
ofstream outFile;
outFile.open("carinfo.txt");
cout<<"Enter the make and model of automobile: ";
cin.getline(automobile,50);
cout<<"Enter the model year: ";
cin>>year;
cout<<"Enter the original asking price: ";
cin>>a_price;
d_price=0.913*a_price;
//cout<<fixed;
cout.precision(2);
cout.setf(ios::showbase||ios::showpoint);
cout<<"Make and model: "<<automobile<<endl;
cout<<"Year: "<<year<<endl;
cout<<"Was asking $"<<a_price<<endl;
cout<<"Now asking $"<<d_price<<endl;
//outFile<<fixed;
outFile.precision(2);
outFile.setf(ios::showbase||ios::showpoint);
outFile<<"Make and model: "<<automobile<<endl;
outFile<<"Year: "<<year<<endl;
outFile<<"Was asking $"<<a_price<<endl;
outFile<<"Now asking $"<<d_price<<endl;
outFile.close();
return 0;
}