-0.271272 0.057637 -1.169941 -0.595656 -1.034938 -2.084308 -1.636656 -0.379287 0.004293 0.289059 0.519261 0.471439 0.571174 0.021626 0.110812 0.810365 0.856656 -0.149288 0.047479 0.215580 -0.163080 -0.832364 -1.017397 -0.769935 -0.434539 -0.555873 -0.462823 -0.662093 0.404535 0.167199 -0.156460 -0.272831 -0.438901 0.469157 0.484331 0.497634 0.012820 -0.359225 -1.001581 -0.702035 -1.427914 -1.775163 -1.531204 -1.519546 -1.839334 -1.734282 -0.865233 -1.666558 -2.260154 -1.655687 -1.768353 -2.065409 -1.846770 -1.859222 -1.720874
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iterator>
using namespace std;
void main()
{
vector<vector<double> > v;
ifstream in("c:\\hh.dat");
double tmp;
v.push_back(vector<double>());
vector<double>* p = &v.back();
while(!in.eof()){
in >> tmp;
p->push_back(tmp);
if(in.peek() == '\n'){
v.push_back(vector<double>());
p = &v.back();
}
}
for(int i = 0; i < v.size(); ++i){
copy(v[i].begin(), v[i].end(), ostream_iterator<double>(cout, " "));
cout << "#####****" << endl;
}
#include <iostream.h>
#include <fstream.h>
#include <afxtemplel.h>
main()
{
FILE* fp;
char name[256];
strcpy(name,fileName.ConvertToChar());
cout << name << endl << flush;
if((fp=fopen(name,"r"))==NULL)
{
cout<<"This file is not opened!"<<endl << flush;
return;
}
cout << "open file success!" << endl << flush;
ifstream in(name,ios::in);
int i = 0;
char line[255];
char *token = NULL;
char seps[] = " ,\t\n";//delimiters in the asc files“空格或逗号”分隔符
CArray<double,double&> *line_mArr=new CArray<double,double&> [50];//最多50行
int arr_counter=0;//行计数
int Point_Counter =0;//点计数
while (fgets(line,255,fp)!=NULL)
{
if(!strcmp(line,"\n")) continue;//遇到空行,但是未到文件结尾。
token=strtok(line,seps);
while(token = strtok(NULL,seps)!=EOF)
{
line_mArr[arr_counter].Add(strtok(NULL,seps));//提取读入的一个数的串到数组中
}
arr_counter++;
}
for(int j=0;j<arr_counter;j++)
{
Point_Counter+=line_mArr[j].GetSize();
}
cout << "Point num = "<< Point_Counter <<endl;//输出点的总数
fclose(fp);
return;
}
已修订,enjoy it!
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iterator>
using namespace std;
void main()
{
vector<vector<double> > v;
ifstream in("c:\\hh.dat");
double tmp;
char dummy;
v.push_back(vector<double>());
vector<double>* p = &v.back();
while(!in.eof()){
while(in.peek() == ' ') in.read(&dummy, 1); //eat space
if(in.peek() == '\n'){
v.push_back(vector<double>());
p = &v.back();
}
in >> tmp;
p->push_back(tmp);
}
cout <<"\n========== result ============" << endl;
cout.precision(10);
for(int i = 0; i < v.size(); ++i){
copy(v[i].begin(), v[i].end(), ostream_iterator<double>(cout, " "));
cout << "#####****" << endl;
}
}
posted on 2007-06-15 14:43
聂文龙 阅读(4055)
评论(3) 编辑 收藏 引用 所属分类:
c++