[英]C++ meaning of String^
我正在尝试为标签(Windows窗体)制作一个getter。
在myForm.h中 :
public: String^ getLabel1() { return label1->Text; };
但是当我尝试打印它时,它将无法编译!
在myForm.cpp中 :
void Main(array<String^>^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Test::MyForm form;
Application::Run(%form);
form.setLabel1();
std::cout << form.getLabel1() << std::endl;
}
我想我返回了错误的类型(String ^),但我在'^'字符上找不到任何内容,当我尝试返回一个std::string
,我无法编译它! 有人能帮我吗?
String^
是“引用GC对象” - 存在于Managed Heap中的对象(即“.NET对象”)。 与String*
(指向System::String
CLR对象或std::string
(C ++标准库字符串本地)的指针相比)。
C ++ STL cout
流不支持输出System::String
,您必须首先将其封送到兼容类型,或者使用Console::WriteLine
。
要重新迭代sp2danny在评论中所说的内容,这不是 C ++,这是C ++ / CLI,它可以被认为是C ++ + C语言替代C#的C语言,有利于能够使用现有的C ++代码源形式,包括STL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.