请教C++程序中的ifstream infile
#include"myStruct.h"
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
void readNfile(vector<nav_sat>& vn)
{
time_gps GregToGps(time_calendar tc);//声明时间转换
char *p, name[20];
p=name;
cout<<"Enter N file name:";
scanf("%s",p);
ifstream infile1(p,ios::in);
if(! infile1)
{
cerr<<"open error!"<<endl;
exit(1);//打开文件失败
}
////////////////////////////////////////////////////////
string strs;//not good declared,暂时轮换存放取得的字符
do
{
getline(infile1,strs);//没有读文件头
} while(strs.substr(60,3)!="END");
//go on reading...
while(!infile1.eof())//当不是文件末尾的时候,一直读
{
pare_s_clock paresclk;//卫星钟差三参数&TOC
time_calendar tc1;//TOC
time_gps tg1;
getline(infile1,strs);//读一行
nav_sat navsat;//定义结构:代表一颗卫星的导航数据
string str2=strs.substr(2,3);//提取3个字符--year
tc1.year=atoi(str2.c_str());//字符转数值
str2=strs.substr(5,3);//提取--month
tc1.month=atoi(str2.c_str());
str2=strs.substr(8,3);//提取--day
tc1.day=atoi(str2.c_str());
str2=strs.substr(11,3);//提取--hour
tc1.hour=atoi(str2.c_str());
str2=strs.substr(14,3);//提取--minute
tc1.minute=atoi(str2.c_str());
str2=strs.substr(17,5);//提取--second
tc1.second=atoi(str2.c_str());
tg1=GregToGps(tc1);//转换为GPS时间
paresclk.TOC.num_week=tg1.num_week ;
paresclk.TOC.num_sec=tg1.num_sec;
str2=strs.substr(22,19);//卫星钟的偏差
paresclk.a0=atof(str2.c_str());
str2=strs.substr(41,19);//卫星钟的漂移
paresclk.a1=atof(str2.c_str());
str2=strs.substr(60,19);//卫星钟的漂移速度
paresclk.a2=atof(str2.c_str());
str2=strs.substr(0,2);//提取--卫星号
navsat.PRN=atoi(str2.c_str());
navsat.pare_clock=paresclk;//单个卫星数据组第一行读完
不管p指针输入什么,程序一直会输出"open error!"