Dears
I have this class which reads a file and should return multidim array.
How can I return the array hb_field and be able to use in main()
class
main()
I have this class which reads a file and should return multidim array.
How can I return the array hb_field and be able to use in main()
class
Code:
class HBSeqFile
{
public:
HBSeqFile();
string HBReadFile();
private:
int counter1;
int counter2;
int strln;
int lpos;
int rpos;
fstream filename;
string TempStr;
string hb_line[4];
string hb_field[4][6];
};
HBSeqFile::HBSeqFile()
{
counter1=0;
counter2=0;
strln=0;
lpos=0;
rpos=0;
};
string HBSeqFile::HBReadFile()
{
//Read line from file and fill in array
filename.open ("c:\\data.txt",ios::in);
if (!filename.is_open())
{
cout<<"File was not opened successfully.\n\n";
}
while(getline(filename, TempStr))
{
hb_line[counter1]=TempStr;
counter1++;
//cout<<hb_line[counter1-1]<<"-"<<endl;
}
filename.close();
for (int f=0; f<counter1; ++f)
{
strln=hb_line[f].length();
lpos=0;
rpos=0;
counter2=0;
for (int i=0; i<strln; ++i)
{
string sc(hb_line[f],i,1);
if(sc==";")
{
rpos=i;
string sc(hb_line[f],lpos,rpos-lpos);
lpos=rpos+1;
hb_field[f][counter2]=sc;
counter2++;
}//endif
}//end for
}//end for
return hb_field;
}//End of Function
Code:
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <fstream>
#include "seqfile.h"
void main()
{
//*Declarations
string ts;
int i;
HBSeqFile HSF;
ts=HSF.HBReadFile();
//cout<<ts;
for (int i=0; i<4; ++i)
{
for (int t=0; t<6; ++t)
{
cout<<ts[i][t]<<"\n"<<endl;
}
}
system("PAUSE");
}//end of main