我的程序从.csv文件中读取数据,当数据格式正确时,它可以正常工作,但我想知道是否可以:
检查加载的数据是否只有数字(假设程序,数据不能是字母表的字母)
检查我们是否加载空行
加载的字符数,例如8。
如果是这样,我该怎么做?
int main(){
ifstream ip('table.csv');
if(!ip.is_open()){
cout << "ERROR" << endl;
}
int n = 3926;
const int CAPACITY = 3926;
const int CAPACITY2 = 7;
string multi [CAPACITY][CAPACITY2];
float TABLE[CAPACITY][CAPACITY2];
if(ip.good()){
for ( int i=0; i<=3925; i++)
{
int k=0;
getline(ip, multi[i][k], ',');
getline(ip, multi[i][k+1], ',');
getline(ip, multi[i][k+2], ',');
getline(ip, multi[i][k+3], ',');
getline(ip, multi[i][k+4], ',');
getline(ip, multi[i][k+5], ',');
getline(ip, multi[i][k+6], '\n');
// change from char to float
TABLE[i][k] = atof(multi[i][k].c_str());
TABLE[i][k+1] = atof(multi[i][k+1].c_str());
TABLE[i][k+2] = atof(multi[i][k+2].c_str());
TABLE[i][k+3] = atof(multi[i][k+3].c_str());
TABLE[i][k+4] = atof(multi[i][k+4].c_str());
TABLE[i][k+5] = atof(multi[i][k+5].c_str());
TABLE[i][k+6] = atof(multi[i][k+6].c_str());
}
}