1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 0
1 0 0 0 0 0
0 0 0 0 0 1
0 1 1 1 1 1
1 1 1 1 1 1
fscanf(f,"%d", &temp);
#include <QVector>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QStringList>
#include <iostream>
const QString allFileToString(QFile &aFile)
{
if (!aFile.open(QFile::ReadOnly | QFile::Text)) {
std::cout << "Error opening file!" << std::endl;
return NULL;
}
QTextStream in(&aFile);
return in.readAll();
}
void setDataToVector(const QStringList &aStringList,
QVector< QVector <int> > &aVector)
{
size_t x = aStringList.size() - 1; // Count of line, 8
size_t y = aStringList.at(0).count("\t") + 1; // Count of digits in line, 6
for (size_t i = 0; i < x; ++i) {
QVector<int> temp_vector;
for (size_t j = 0; j < y; ++j) {
temp_vector.push_back(aStringList.at(i).split("\t").at(j).toInt());
}
aVector.push_back(temp_vector);
}
}
void printVector(const QVector< QVector <int> > &aVector)
{
for (int i = 0; i < aVector.size(); ++i) {
for (int j = 0; j < aVector.at(0).size(); ++j) {
std::cout << aVector.at(i).at(j) << "\t";
}
std::cout << std::endl;
}
}
int main(/*int argc, char *argv[]*/)
{
QVector< QVector <int> > vector;
QFile file("test.txt");
setDataToVector(allFileToString(file).split("\n"), vector);
printVector(vector);
return 0;
}
QFile file("my_file");
file.open(QIODevice::ReadOnly);
QTextStream fileStream(&file);
QString str;
std::vector<std::vector<int>> array;
for (str = fileStrea.readLine(); !str.isNull(); str = fileStream.readLine()) {
array.push_back(std::vector<int>);
std::vector<int>& curr = array.back();
QTextStream strStream(str);
while(!strStream.atEnd()) {
int number;
stdStream >> number;
curr.push_back(number);
}
}