请教C++程序中的ifstream infile

longteng 2012-05-04 09:25:09
#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!"
...全文
1599 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhj2010918 2012-06-26
  • 打赏
  • 举报
回复
5楼的那段程序是什么意思 啊
longteng 2012-05-08
  • 打赏
  • 举报
回复
是啊,我知道大概的原理哦,但是编程什么的还在学习中[Quote=引用 8 楼 的回复:]
c++ 不能写进去

借助api, vc类库吧

ado技术
[/Quote]
bsnry 2012-05-07
  • 打赏
  • 举报
回复
c++ 不能写进去

借助api, vc类库吧

ado技术
longteng 2012-05-07
  • 打赏
  • 举报
回复
怎么写进access
longteng 2012-05-07
  • 打赏
  • 举报
回复
我自己研究起socket来了,目前只做到接收数据对了,怎么处理数据还在看呢
ljhhh0123 2012-05-05
  • 打赏
  • 举报
回复
没问题呀,先做个小程序试试。
#include<iostream>
#include<fstream>

using namespace std;
int main(int argc, char *argv[]) {
char cbuff[256];
cin >> cbuff;
ifstream file1(cbuff, ios_base::binary);
while(file1.getline(cbuff, 256,'\n'))
cout << cbuff << '\n';

return 0;
}
longteng 2012-05-05
  • 打赏
  • 举报
回复
额,不懂您的意思哦[Quote=引用 3 楼 的回复:]
lz 说吧,哪里错了,发段代码给人,
[/Quote]
bsnry 2012-05-05
  • 打赏
  • 举报
回复
lz 说吧,哪里错了,发段代码给人,
开发者说 2012-05-04
  • 打赏
  • 举报
回复
ifstream infile1(p,ios::in);把p换成真实路径的字符串试试
fishion 2012-05-04
  • 打赏
  • 举报
回复
输入的文件得先存在才行

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧