字符串尚未声明,QT

Nev*_*ain 5 c++ qt

我正在尝试更改某个文本框消息.它会显示我的输出.

这是我在main()中的内容

#include "form2.h"
....
string recvMSG = "random";
Run Code Online (Sandbox Code Playgroud)

182 :: Form2 :: changeOutput(recvMSG); ...

在我的form2.h中,我有:

#include <string.h>    
#include <iostream>
#include <stdlib.h>    
...
    void Form2::changeOutput(string s)
    {
    QString s1 = i18n(s);
    output_box.setText(s1);

    }
Run Code Online (Sandbox Code Playgroud)

但我仍然得到:.ui/form2.h:56:错误:'string'尚未声明

谢谢.

编辑:: kk所以现在它显示:: TCPClient.cpp:182:错误:无法调用成员函数'virtual void Form2 :: changeOutput(std :: string)'没有对象

sth*_*sth 15

stringstd命名空间中,因此您需要将其引用为std::string,或者您需要使用using namespace std;或在当前范围中使用该名称using std::string;.

调用标题string,不是string.h,所以包括它:

#include <string>
Run Code Online (Sandbox Code Playgroud)

通常,您也可能希望使用QT QString而不是std::string在与通常采用QString参数的QT组件相关联时使用QT .