#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
typedef struct transaction
{
vector<int>read;
}tran;
int main()
{
vector<tran> table;
int count=0;
char s[1000];
ifstream infile;
tran t;
char *p;
infile.open("C:\\Users\\liwei\\Desktop\\MATI\\T2.txt");
if(infile==NULL)
{
cout<<"File is not exist"<<endl;
exit(0);
}
else if(infile.is_open())
{
cout<<"File open succeed."<<endl;
while(infile.getline(s,1000,'\n'))
{
p = strtok(s,",");
while(p)
{
t.read.push_back(atoi(p));
p = strtok(NULL,",");
}
table.push_back(t);
t.read.clear();
}
}
int i,j;
i=j=0;
for(i=0;i<table.size();i++){
for(j=0;j<table[i].read.size();j++){
cout<<table[i].read[j]<<" ";
}
cout<<"第"<<i<<"行"<<endl;
}
infile.close();
}
#include<vector>
#include<fstream>
using namespace std;
typedef struct transaction
{
vector<int>read;
}tran;
int main()
{
vector<tran> table;
int count=0;
char s[1000];
ifstream infile;
tran t;
char *p;
infile.open("C:\\Users\\liwei\\Desktop\\MATI\\T2.txt");
if(infile==NULL)
{
cout<<"File is not exist"<<endl;
exit(0);
}
else if(infile.is_open())
{
cout<<"File open succeed."<<endl;
while(infile.getline(s,1000,'\n'))
{
p = strtok(s,",");
while(p)
{
t.read.push_back(atoi(p));
p = strtok(NULL,",");
}
table.push_back(t);
t.read.clear();
}
}
int i,j;
i=j=0;
for(i=0;i<table.size();i++){
for(j=0;j<table[i].read.size();j++){
cout<<table[i].read[j]<<" ";
}
cout<<"第"<<i<<"行"<<endl;
}
infile.close();
}