So me and my groupmates suddenly have some clutchwork at hand. I was assigned of making an import function that reads through a textfile that looks like this, and store it to a 2D array:
The columns are Tab-separated. As this suddenly came up, dont have the entire project file with me and I am nowhere near my old reliables, I tried conjuring this up in the most generic way possible:
void signal::import_data(string filename){
ifstream file;
file.open(filename.c_str());
if(file.fail()){
cerr << "file open fail" << endl;
}else{
while(!file.eof)
{
for(int j = 0; j < NumCols; j++){
for(int i = 0; i < NumRows; i++){
file >> _data[j][i];
}
}
}
}
file.close();
}
Am I doing this correct? Im not so sure if streaming like this can bypass tabs, or can it?