C读取文件
2024-10-11 18:53:19
C读取文件,这种写法不会多一行。
#include "stdafx.h"
#include <vector>
using namespace std;
struct PointXYZ
{
double X;
double Y;
double Z;
}; int _tmain(int argc, _TCHAR* argv[])
{
FILE* in=fopen("D:\\project60-cut-1000.txt","r");
if(in==NULL)
{
printf("missing file");
return ;
}
double tmp=;
//char buff[255] = {};
float x;
float y;
float z;
vector<PointXYZ> *points=new vector<PointXYZ>();
char* str;
int i=;
// while(!feof(in))
fscanf(in,"%f %f %f",&x,&y,&z);
while(feof(in)==) /*判断是否文件尾,不是则循环*/
{
i++;
PointXYZ point;
point.X=x;
point.Y=y;
point.Z=z;
points->push_back(point);
fscanf(in,"%f %f %f",&x,&y,&z);
}
fclose(in); for (vector<PointXYZ>::iterator iter = points->begin(); iter != points->end(); ++iter)
{
PointXYZ tmp=(PointXYZ)*iter;
printf("%f %f %f\n",tmp.X,tmp.Y,tmp.Z);
}
printf("Number:%d\n",(int)points->size());
system("pause");//getchar();
return ;
}
参考C++的读取
void LoadImages(const string &strAssociationFilename, vector<string> &vstrImageFilenamesRGB,
vector<string> &vstrImageFilenamesD, vector<double> &vTimestamps)
{
ifstream fAssociation;
fAssociation.open(strAssociationFilename.c_str());
while(!fAssociation.eof())
{
string s;
getline(fAssociation,s);
if(!s.empty())
{
stringstream ss;
ss << s;
double t;
string sRGB, sD;
ss >> t;
vTimestamps.push_back(t);
ss >> sRGB;
vstrImageFilenamesRGB.push_back(sRGB);
ss >> t;
ss >> sD;
vstrImageFilenamesD.push_back(sD); }
}
}
最新文章
- 倒计时的js实现 倒计时 js Jquery
- 使用OFBIZ 时,使用的键入提示。
- bootstrap学习笔记之二
- vim 学习记录2
- IOS中控制器的重要方法使用
- *MySQL卸载之后无法重装,卡在Apply security settings:Error Nr.1045
- Eclipse常用插件推荐
- Spring (二) OOP V.S AOP
- 慢查询日志分析(mysql)
- 一个ExtJS实例
- 【Qt编程】基于Qt的词典开发系列<;十二>;调用讲述人
- Android版数据结构与算法(一):基础简介
- 蓝桥杯刷题,第四界省赛B组
- C# 使用密码连接Redis
- 带你领略Linux系统发展及版本更迭
- 一个前端开发者换电脑的过程(git篇)
- mybatis-generator插件执行报错:Cannot resolve classpath entry
- linux学习之uniq
- Certificate Formats | Converting Certificates between different Formats
- SharePoint Framework 企业向导(一)