This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*ファイルを開開く | |
*区切り文字で分解 | |
*表示 | |
*/ | |
#include "mainwindow.h" | |
#include <QApplication> | |
#include <QFile> | |
#include <QDebug> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
MainWindow w; | |
w.show(); | |
QFile file( "D:\\qt\\data.csv" );//フルパスでファイルを指定 | |
//QFile file( "data.txt" );// ビルドディレクトリの中のdata.txt | |
if (!file.open(QIODevice::ReadOnly))//読込のみでオープンできたかチェック | |
{ | |
qDebug() << "can not open file." ; | |
return 0; | |
} | |
QString str; | |
QTextStream in(&file); | |
str = in.readAll();//全文読込 | |
//区切り文字で分解 | |
QStringList list = str.split(','); | |
// QStringList の表示 Indexing: | |
for(int n = 0;n < list.size();++n){ | |
qDebug() << list.at(n) ; | |
} | |
qDebug() << "---------------- QStringList の表示 Java-style iterator: の場合----------------" ; | |
QStringListIterator javaStyleIterator(list); | |
while (javaStyleIterator.hasNext()) | |
qDebug() << javaStyleIterator.next() ; | |
qDebug() << "---------------- QStringList の表示STL-style iterator: の場合----------------" ; | |
QStringList::const_iterator constIterator; | |
for (constIterator = list.constBegin(); constIterator != list.constEnd(); | |
++constIterator) | |
qDebug() << (*constIterator) ; | |
return a.exec(); | |
} |
0 件のコメント:
コメントを投稿