在QT 5.12中直接使用cout将提示错误如下:

添加库 #include<iostream>,并将cout&end改为std::cout&std::endl

代码如下:

 #include "mainwindow.h"
#include<iostream>
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show(); std::cout <<"hello world" << std::endl; return a.exec();
}

此时错误警告消失,但是仍无窗口输出;

在qt的工程文件(.pro文件)中加入以下代码:

CONFIG += console

代码如下:

 #-------------------------------------------------
#
# Project created by QtCreator --05T16::
#
#------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, ): QT += widgets TARGET = VCICAN
TEMPLATE = app # The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0. CONFIG += c++
CONFIG += console SOURCES += \
main.cpp \
mainwindow.cpp HEADERS += \
mainwindow.h FORMS += \
mainwindow.ui # Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target DISTFILES +=

此时cout函数可正常运行

参考:

https://blog.csdn.net/u014563989/article/details/44537727

https://zhidao.baidu.com/question/143715512.html

http://blog.sina.com.cn/s/blog_4f183d960100sdxf.html

http://www.qtcn.org/bbs/simple/?t21816.html

QT use of undeclared identifier 'cout'的更多相关文章

  1. iomanip,setw(),setw: undeclared identifier

    今天使用setw(),提示setw: undeclared identifier,上网查了下,原来是没有包含头文件iomanip,现摘录如下: iomanip #include <iomanip ...

  2. 【原】iOS 同时重写setter和getter时候报错:Use of undeclared identifier '_name';did you mean 'name'

    写了那么多的代码了,平时也没有怎么注意会报这个错误,因为平时都很少同时重写setter和getter方法,一般的话,我们大概都是使用懒加载方法,然后重写getter方法,做一个非空判断.然后有时候根据 ...

  3. error C2065: 'assert' : undeclared identifier

    F:\VC6.0 : error C2065: 'assert' : undeclared identifier 导入#include <assert.h>

  4. 使用某些Widows API时,明明包含了该头文件,却报错“error C2065: undeclared identifier”

    在使用一些新版本的API,或者控件的新特性(比如新版的ComCtl32.dll)的时候,你可能会得到“error C2065: undeclared identifier.“这个错误.原因是这些功能是 ...

  5. loadrunner场景报错:Error: CCI compilation error -/tmp/brr_5d65oV/netdir/E/\320\324/Action.c (318): undeclared identifier `LAST'解决思路

    在windows下写的脚本编译通过 但是拿到linux agent场景执行中就会提示如下,同样的脚本在windows agent下没有任何问题 agent连的是linux负载机 通过脚本一行一行排查, ...

  6. use of undeclared identifier 'xxxxxxx方法名'

    在*.m文件中,编写一个方法,出现了 use of undeclared identifier 'xxxx方法名'.   遇到这种情况: 首先要看,*.h 文件是否定义了该方法. 其次,要检查一下,方 ...

  7. 蛋疼的Action.c (141): undeclared identifier `LAST'异常

    之前这个脚本运行了很久都没有问题,今天突然在场景运行不了: Action.c (141): undeclared identifier `LAST' 害的老子一直在纠结,这个关联函数没有问题啊,怎么一 ...

  8. error C2065: 'CArchiveStream' : undeclared identifier

    release:模式下 问题: 在导入JPEG文件时要使用到  CArchiveStream类  但是编译的时候会出现  'CArchiveStream'   :   undeclared   ide ...

  9. error C2065: ‘_bstr_t’ : undeclared identifier

    转自VC错误:http://www.vcerror.com/?p=828 问题描述: error C2065: '_bstr_t' : undeclared identifier 解决方法: 详细的解 ...

随机推荐

  1. CSS3实现穿墙广告效果

    ㈠分享一组很有趣的代码: 具体如下: <!doctype html> <html> <head> <meta charset="UTF-8" ...

  2. 2、DockPanel

    DockPanel——停靠面板,内部控件或容器可以放置在上.下.左(默认).右.类似于Java AWT布局中的BorderLayout. 但与BorderLayout不同的是,每一个区域可以同时放置多 ...

  3. 运行时错误:“stack around the variable…was corrupted”

    造冰箱的大熊猫@cnblogs 2018/11/1 引发问题的代码片段如下 WORD var; scanf ( "%d", &var ); 包含上述代码的程序,编译正常,运 ...

  4. Confluence 6 插入一个文件到你的页面

    文件可以在页面中以缩略图或者链接的方式显示.我们有多种办法能够上传文件,请参考 Upload Files 页面. 你可以控制文件如何在你的页面中显示.文件在页面中显示的可用方法与你的文件类型有关. 插 ...

  5. sh_07_元组遍历

    sh_07_元组遍历 info_tuple = ("zhangsan", 18, 1.75) # 使用迭代遍历元组 for my_info in info_tuple: # 使用格 ...

  6. BZOJ 4849 [NEERC2016]Mole Tunnels (模拟费用流)

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=4849 题解 其实也是模拟费用流,但是这道题和一般的题目不一样,这道题是在一个完全二叉树上 ...

  7. Jmeter -- 添加断言,及断言结果

    步骤: 1. 添加响应断言(添加-断言-响应断言) Add -->  Assertions --> Response Assertion 2. 配置断言 判断响应内容中,是否包含关键字“禅 ...

  8. Pandas使用groupby()时是否会保留顺序?

    PythonPandas:使用groupby()和agg()时是否保留了顺序? 看到这个增强问题 简短的答案是肯定的,groupby会保留传入的顺序.你可以用你的例子来证明这一点: df = pd.D ...

  9. HTML和CSS 入门系列(二):文字、表单、表格、浮动、定位、框架布局、SEO

    上一篇:HTML和CSS 入门系列(一):超链接.选择器.颜色.盒模式.DIV布局.图片 一.文字 1.1 属性 1.2 字体样式:font-family 1.3 字体大小:font-size 1.4 ...

  10. Docker入门-常用命令

    Docker镜像操作 Docker运行容器前需要本地存在对应的镜像,如果本地不存在该镜像,Docker会从镜像仓库下载该镜像. 获取镜像 从Docker镜像仓库获取镜像的命令是docker pull. ...