Created
December 28, 2013 22:44
-
-
Save yamato8/8165174 to your computer and use it in GitHub Desktop.
Qt:区切り文字で分解
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\\qtTest\\data.txt" );//OK | |
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(','); | |
//qDebug() << list.at(0) ; | |
// QStringList の表示 Indexing: | |
for(int n = 0;n < list.size();++n){ | |
qDebug() << list.at(n) ; | |
} | |
// QStringList の表示 Java-style iterator: | |
QStringListIterator javaStyleIterator(list); | |
while (javaStyleIterator.hasNext()) | |
qDebug() << javaStyleIterator.next() ; | |
// QStringList の表示 STL-style iterator: | |
QStringList::const_iterator constIterator; | |
for (constIterator = list.constBegin(); constIterator != list.constEnd(); | |
++constIterator) | |
qDebug() << (*constIterator) ; | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment