我不能在我的程序中声明一个字符串:
string MessageBoxText = CharNameTextBox->Text;
它只是行不通。它说 string is undeclared identifier
。我在命名空间或包含或类似的东西中缺少什么?
最佳答案
确保你已经包含了这个标题:
#include <string>
然后使用std::string
代替string
。这是因为 string
是在 std
命名空间中定义的。
并且不要在命名空间范围内编写:
using namespace std; //bad practice if you write this at namespace scope
然而,在函数范围内编写它并没有那么糟糕。但最好的是我之前建议的:
使用 std::string
作为:
std::string MessageBoxText = CharNameTextBox->Text;
关于c++ - 为什么我不能在我的程序中声明一个字符串 : "string is undeclared identifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7625105/