main.cpp
来自「Qt4源代码,详细介绍了Qt4编程中的范例」· C++ 代码 · 共 40 行
CPP
40 行
#include <iostream>#include <QtCore>using namespace std;int main(int argc, char *argv[]){ QCoreApplication app(argc, argv); QStringList capList; int pos; bool matched; //QRegExp rx("[A-Za-z_]+[A-Za-z_0-9]*"); QRegExp rx("\\b(\\w+)\\W+\\1\\b"); if(!rx.isValid()) { cout << qPrintable(rx.errorString()); return -1; } QFile file("main.cpp"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return -1; QTextStream in(&file); while (!in.atEnd()) { QString str = in.readLine(); pos = 0; matched = false; while ((pos = rx.indexIn(str, pos)) != -1) { capList = rx.capturedTexts(); cout << qPrintable(capList.at(0)) << "\t"; pos += rx.matchedLength(); matched = true; } if(matched) cout << endl; } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?