Files
HandWritten-Analisys/测试/本机测试/转换图像文件到jpg/read_scanf.cpp
yanshui177 962de04ffb 笔迹鉴别程序
考试的笔迹鉴别程序,分辨出不同人写的笔迹
2017-05-17 16:50:37 +08:00

26 lines
655 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能将filename 中的数据共cols列读取到_vector中_vector可视为二维数组
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int read_scanf(const string &filename,const int &cols,vector<double *> &_vector)
{
FILE *fp=fopen(filename.c_str(),"r");
bool flag=true;
int i=0;
if(!fp) { cout<<"File open error!\n"; return 0; }
while(flag)
{
double *ptr=new double[cols];
for(i=0;i<cols;i++)
{ //读取数据存在_vector[cols]中
if(EOF==fscanf(fp,"%lf",&ptr[i])){flag=false;break;};
if(EOF==fgetc(fp)){flag=false;i++;break;}
}
if(cols==i) _vector.push_back(ptr);
}
fclose(fp);
return 1;
}