Originally Posted by
jacek
Does this mean that, if you comment out lines with QApplication and QMessageBox, it works OK? Or do you also change the way you build your project?
The comment meant to say that the c++ portions of the code are valid.
Commenting out those lines does not correct the problem.
Here is the build file:
DEFINES += QT_NO_DEBUG_OUTPUT
TEMPLATE = app
TARGET = test
DEPENDPATH += .
INCLUDEPATH += .
SOURCES += main.cpp
DEFINES += QT_NO_DEBUG_OUTPUT
TEMPLATE = app
TARGET = test
DEPENDPATH += .
INCLUDEPATH += .
SOURCES += main.cpp
To copy to clipboard, switch view to plain text mode
Using the same build method, the following also demonstrates the same problem.
//#include <QString>
//#include <QMessageBox>
//#include <QApplication>
#include <string>
#include <fstream>
#include <vector>
using std::endl;
using std::string;
using std::ifstream;
using std::ofstream;
using std::streamsize;
using std::vector;
int main (int argc, char* argv[])
{
//QApplication app (argc, argv);
ofstream OF;
OF.open("testdata.txt");
for (int i = 1; i <= 10; ++i)
{
OF << "test line " << i << endl;
}
OF.close();
vector<string> vec;
ifstream IF;
IF.open("testdata.txt");
string line;
streamsize pos;
while (IF.good())
{
getline (IF, line);
IF.peek();
pos = IF.tellg();
printf("%s\n", line.c_str());
//QMessageBox::information(0, "line", QString::fromStdString(line));
vec.push_back(line);
}
IF.close();
ofstream OF2;
OF2.open("testdata2.txt");
for (size_t i = 0; i < vec.size(); ++i)
{
OF2 << vec[i] << endl;
}
OF2.close();
return 0;
}
//#include <QString>
//#include <QMessageBox>
//#include <QApplication>
#include <string>
#include <fstream>
#include <vector>
using std::endl;
using std::string;
using std::ifstream;
using std::ofstream;
using std::streamsize;
using std::vector;
int main (int argc, char* argv[])
{
//QApplication app (argc, argv);
ofstream OF;
OF.open("testdata.txt");
for (int i = 1; i <= 10; ++i)
{
OF << "test line " << i << endl;
}
OF.close();
vector<string> vec;
ifstream IF;
IF.open("testdata.txt");
string line;
streamsize pos;
while (IF.good())
{
getline (IF, line);
IF.peek();
pos = IF.tellg();
printf("%s\n", line.c_str());
//QMessageBox::information(0, "line", QString::fromStdString(line));
vec.push_back(line);
}
IF.close();
ofstream OF2;
OF2.open("testdata2.txt");
for (size_t i = 0; i < vec.size(); ++i)
{
OF2 << vec[i] << endl;
}
OF2.close();
return 0;
}
To copy to clipboard, switch view to plain text mode
contents of testdata.txt:
test line 1
test line 2
test line 3
test line 4
test line 5
test line 6
test line 7
test line 8
test line 9
test line 10
contents of testdata2.txt
test line 1
2
e 3
ne 4
ine 5
line 6
line 7
t line 8
st line 9
est line 10
Bookmarks