|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
if(!fout.is_open());
每次都是打开失败然后退出,去掉后就写入信息了
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- void fileit(ostream&os,double fo,const double fe[],int n);
- const int LIMIT = 5;
- int main()
- {
- ofstream fout;
- const char * fh ="1.txt";
- fout.open(fh);
- if(!fout.is_open());
- {
- system("pause");
- exit(EXIT_FAILURE);
- }
- double objective;
- cout<<"Enter the focal length of your telescopr objective in mm";
- cin>>objective;
- double eps[LIMIT];
- cout<<"Enter the focal lengths, in mm, of "<<LIMIT<<"eyepieces:\n";
- for(int i = 0;i < LIMIT;i++)
- {
- cout<<"Eyepices #"<<i + 1<<": ";
- cin>>eps[i];
- }
- fileit(fout,objective,eps,LIMIT);
- fileit(cout,objective,eps,LIMIT);
-
- system("pause");
- return 0;
-
- }
- void fileit(ostream&os,double fo,const double fe[],int n)
- {
- ios_base::fmtflags initial;
- initial = os.setf(ios_base::fixed);
- os.precision(1);
- os.width(12);
- os<<"f.1. eyepiece";
- os.width(15);
- os<<"magnification"<<endl;
- for(int i = 0;i < n;i++)
- {
- os.width(12);
- os<<fe[i];
- os.width(15);
- os<<int(fo/fe[i] + 0.5)<<endl;
- }
- os.setf(initial);
- }
复制代码 |
|