- 论坛徽章:
- 0
|
- #include <fstream>;
- #include<stdlib.h>;
- #include <iostream>;
- using namespace std;
- float get_fits_exposuretime (char *file)
- {
- char *ch=new char [4101];
- char *timeask= new char [22];
- char *temp= new char [22];
- float time;
- ifstream fin(file);
- fin.seekg(0);
- fin.read(ch,4100);
- timeask=strstr(ch,"EXPOSURE")+9;
- delete [] ch;
- *(timeask+22)='\0';
- temp=strstr(timeask,"'");
- if(temp==NULL)
- {
- time=atof(timeask);
- }
- else
- {
- timeask=temp+1;
- temp=strstr(timeask,"'");
- *(temp)='\0';
- time=atof(timeask);
- }
- fin.close();
- // delete [] timeask;
- // delete [] temp;
- return time;
- }
- int main ()
- {
- char file[20];
- float time;
- cout << "enter fits file name:";
- cin >;>; file;
- time=get_fits_exposuretime(file);
- cout<<time<<endl;
- }
复制代码
(该程序用于从一个文件中读字符串,然后转成float类型)
为什么我把上面注释掉的两行放开就回出现段错误的问题,而注释掉就没有问题? |
|