Witam, uczę się Qt z książki: https://helion.pl/ksiazki/c-i-qt-wprowadzenie-do-wzorcow-projektowych-wydanie-ii-alan-ezust-paul-ezust,cppqtw.htm#format/e
Jak na razie często napotykam problemy... Sprawa wygląda to tak:
main.cpp
#include <QTextStream>
#include <QString>
#include <QFile>
#include <iostream>
QTextStream cout(stdout);
QTextStream cerr(stderr);
QTextStream cin(stdin);
int main() {
///---------------------------------------------------------------
QString str, newstr;
QTextStream strbuf(&str);
int lucky = 7;
float pi = 3.14f;
double e = 2.71;
cout << "Strumien w pamieci" << "\r\n";
strbuf << "szczesliwy_numerek: " << lucky
<< "\r\npi: " << pi
<< "\r\ne: " << e << "\r\n";
cout << str;
///---------------------------------------------------------------
QString fileName;
cout<<"Podaj nazwe pliku: ";
cin >> fileName;
QFile data(fileName);
if(data.open(QIODevice::ReadOnly)){
cout<<"Plik istnieje, czy go nadpisac? [1/0]"<<endl;
int c;
cin>>c;
if(c==0)
return 0;
}
data.close();
data.open(QIODevice::WriteOnly);
QTextStream out(&data);
out << str;
data.close();
///---------------------------------------------------------------
cout << "Odczyt danych z pliku: UWAGA na bledy!" << endl;
if(data.open(QIODevice::ReadOnly)) {
QTextStream in(&data);
int lucky2;
in >> newstr >> lucky2;
if (lucky != lucky2)
cerr << "BLAD! Niepoprawny " << newstr <<" "<< lucky2 << endl;
else
cout << newstr << " OK" << endl;
float pi2;
in >> newstr >> pi2;
if (pi2 != pi)
cerr << "BLAD! Niepoprawny " << newstr << pi2 << endl;
else
cout << newstr << " OK" << endl;
double e2;
in >> newstr >> e2;
if (e2 != e)
cerr << "BLAD! Niepoprawny " << newstr << e2 << endl;
else
cout << newstr << " OK" << endl;
data.close();
}
cout << "Odczyt z pliku linia po linii: " << endl;
///---------------------------------------------------------------
if(data.open(QIODevice::ReadOnly)) {
QTextStream in(&data);
while (!in.atEnd()) {
newstr = in.readLine();
cout << newstr << endl;
}
data.close();
}
///---------------------------------------------------------------
cin.readLine(); cin.readLine();
return 0;
}
*.pro
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
SOURCES += \
main.cpp
Przykładowe wykonanie programu wygląda tak:

Tak jak by aplikacja nie działała po kolei... najpierw mam podać strumień wejściowy ( po kodzie widać że tak nie powinno być ), dopiero potem w konsoli pokazywane jest to co powinno być wyświetlone wcześniej, a potem z jakiegoś powodu już wszystko działa normalnie :/
W razie czego nie używam std::cout, std::cin itd... lecz:
QTextStream cout(stdout);
QTextStream cerr(stderr);
QTextStream cin(stdin);
Z góry dziękuje wam za pomoc :)