2011-10-02 56 views

回答

13

确保你已经包括这个头:

#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; 
+0

我在哪里把它放在我的程序中,我已经尝试过,但我只是在无论放哪里的地方都会遇到一百行错误 – Trent

+0

它需要位于文件顶部的任何其他代码之外。也许发布一些代码? – 2011-10-02 07:32:13

+0

std :: string是否工作? – 2011-10-02 07:32:28

3

要使用标准string类在C++中,你需要#include <string>。一旦添加了#include指令,string将在std名称空间中定义,您可以将其作为std::string来引用。

E.g.

#include <string> 
#include <iostream> 

int main() 
{ 
    std::string hw("Hello, world!\n"); 
    std::cout << hw; 
    return 0; 
} 
+0

我刚刚编辑斯科特的答案,使更好,然后刷新页面,它也显示了你的。 +1。 – Nawaz

相关问题