Qt using cout, CIN, Cerr

Source: Internet
Author: User

In Qt, the most used is the GUI page, but the GUI is slow, some small test may wish to use the console first, of course, in QT can directly use cout, cin these. It may not be compatible with some types of QT, such as Qbytearray. Looked up on the internet, found that the following methods can be used to output.

You first need to include the following header files:

#include <QTextStream>

#include <stdio.h>

Then, before using CIN, cout, Cerr, create the following variables:

Qtextstream Cin (stdin, qiodevice::readonly);

Qtextstream cout (stdout, qiodevice::writeonly);

Qtextstream Cerr (stderr, qiodevice::writeonly);

Among them, Qtextstream is a very useful string processing class, it can make a string or character-based device, file processing becomes very convenient.

You can then use the CIN, cout, Cerr classes in the qstring environment, just like normal C + +. It is important to note that such cin, cout, Cerr and we encountered in the traditional C + + is a little different, that is, you cout a qstring, the default is not directly output, it is generally necessary to wait until the cout buffer full, before the terminal output of the internal string If you want to see the output immediately after cout, you can either output a endl after the output, or call cout's internal method flush, forcing the condition buffer, for example:

QString str;

str = "Hello world!";

cout<<str;

Cout.flush ();

cin>>str;

cout<<str<<endl;

Qt using cout, CIN, Cerr

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.