G:\Vmware\shared_folders\QT\day02\Simple_calculator\mainwindow.cpp:39: error: 'string' was not declared in this scope string str = ui->lineEdit->text().toStdString(); ^~~~
时间: 2023-09-10 07:05:27 浏览: 48
这个错误是因为在您的代码中未正确声明 `string` 类型。`string` 类型属于 C++ 标准库 `std` 命名空间中的一个类,所以您需要包含 `<string>` 头文件并使用 `std::string` 来声明变量。
要解决这个问题,您可以在文件开头添加以下代码:
```cpp
#include <string>
```
然后将第39行的代码修改为:
```cpp
std::string str = ui->lineEdit->text().toStdString();
```
这样就可以正确地声明和使用 `std::string` 类型了。