gpt4 book ai didi

c++ - 字符串还没有声明,QT

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:52 26 4
gpt4 key购买 nike

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

这就是我的 main() 中的内容

#include "form2.h"
....
string recvMSG = "random";

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);

}

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

谢谢。

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

最佳答案

string 位于 std 命名空间中,因此您需要将其称为 std::string,或者您需要当前作用域中可用的名称 using namespace std;using std::string;

此外, header 名为 string,而不是 string.h,因此以这种方式包含它:

#include <string>

通常,如果您将 QT 的 QString 与通常采用 QString 参数。

关于c++ - 字符串还没有声明,QT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1808540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com