为什么我不能在程序中声明字符串:"string is undeclared identifier"? [英] Why can't I declare a string in my program: "string is undeclared identifier"
本文介绍了为什么我不能在程序中声明字符串:"string is undeclared identifier"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在程序中声明字符串:
I can't declare a string in my program:
string MessageBoxText = CharNameTextBox->Text;
那是行不通的.它说 string是未声明的标识符
.我在命名空间中缺少什么或包含或类似的东西?
it just doesn't work. It says string is undeclared identifier
. What am I missing in the namespace or include or something like that?
推荐答案
确保已包含此标头:
#include <string>
然后使用 std :: string
而不是 string
.这是因为 string
是在 std
命名空间中定义的.
And then use std::string
instead of string
. It is because string
is defined in std
namespace.
也不要在命名空间范围内编写此代码:
And don't write this at namespace scope:
using namespace std; //bad practice if you write this at namespace scope
但是,在函数范围内编写它并不坏.但是最好的是我之前建议的:
However, writing it at function scope is not that bad. But the best is one which I suggested before:
将 std :: string
用作:
Use std::string
as:
std::string MessageBoxText = CharNameTextBox->Text;
这篇关于为什么我不能在程序中声明字符串:"string is undeclared identifier"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文