#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
class csvdata{
public:
int id;
int level;
float price;
float cost;
};//行的类定义
int main()
{
vector<csvdata> incsv;
csvdata intp;
FILE *fp;
fp=fopen("price.csv","r");
if( fp == NULL)
{
cout << "price.csv is not exsit!\n";
exit(1);
}
while(1){
fscanf(fp,"%d,%d,%f,%f",&intp.id,&intp.level,&intp.price,&intp.cost);
incsv.push_back(intp);
if (feof(fp)) break;
}
fclose(fp);
for(int i=0;i<incsv.size();i++)
{
cout<<incsv[i].id<<" "<<incsv[i].level<<" "<<incsv[i].price<<" "<<incsv[i].cost<<endl;
}//输出显示每行的数据
//system("pause");
//fclose(fp);
return 0;
}
打开的文件在附件上,帮忙看一下,哪里错了?
--
FROM 124.78.13.*