I am using RHEL5.4, QT4.8 Only the first line of the file gets handled in the getline. My qDebug on the stringstream ss prints all the lines in the file. my qDebug on the records struct repeats the data in the first line of the file for the total number of lines in the file. My qDebug on the result vector again repeats the data in the first line of the file for the total number of lines in the file.
First I declare a record structure in the header file.
struct data_rec
{
std::string name;
std::string value;
};
std::ifstream myfile("foo.bar");
if(!myfile.is_open()){
qDebug() << "Could not open file";
}else {
qDebug() << "File opened";
std::string line;
std::stringstream ss;
std::stringstream tss;
while(std::getline(myfile,line))
{
data_rec records;
tss.str("");
ss<<line<<std::endl;
tss<<line<<std::endl; //; temp stringstream
std::getline(tss, records.name, ',');
std::getline(tss, records.value, ',');
qDebug()<<"!!!" << records.name.c_str();
qDebug()<<"!!!" << records.value.c_str();
result.push_back(records);
tss.str(std::string());
}
for(int x = 0; x < 46; x++)
{
QString tstr1 = QString::fromStdString(result[i].name);
QString tstr2 = QString::fromStdString(result[i].value);
qDebug() << tstr1 << " -> " << tstr2;
}
qDebug() << QString::fromStdString(ss.str());
qDebug() << "\n////////////////////////////////////////\n";
myfile.close();
}