Qt 控制台输入输出(支持中文)

Qt 控制台输入输出采用 QTextStream(stdin) 和QTextStream(stdout)。QTextStream 类有自己的缓存机制,一般是行缓冲,一行满了才显示,所以加了 endl 之后才会显示,不加的话暂时不会显示,等到 endl 或者程序结束的时候才会显示。
而标准C中可以用 setvbuf(…) 来改变缓存机制,但是 Qt 没有。

#include <QCoreApplication>
#include <QTextStream>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QTextStream qin(stdin);
QTextStream qout(stdout);

QString qstr;
qin>>qstr;
qout<<qstr<<endl;

return a.exec();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
C++ 控制台输入输出(支持中文)
C++ 控制台的输入输出采用 cin 和 cout。

#include <QCoreApplication>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

string str;
cin>>str;
cout<<str;

return a.exec();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C 控制台输入输出(支持中文)
#include <QCoreApplication>
#include <stdio.h>

using namespace std;

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

char str[255];
scanf("%s", str);
printf("%s", str);

return a.exec();
}
————————————————
版权声明:本文为CSDN博主「福州-司马懿」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/chy555chy/article/details/53609178

原文地址:https://www.cnblogs.com/chinasoft/p/15251509.html