[英]C++ meaning of String^
I'm trying to make a getter for a Label (Windows Form). 我正在尝试为标签(Windows窗体)制作一个getter。
In myForm.h : 在myForm.h中 :
public: String^ getLabel1() { return label1->Text; };
But when I try to print it, it won't compile! 但是当我尝试打印它时,它将无法编译!
In myForm.cpp : 在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;
}
I guess I return the wrong type (String^), but i can't find anything on the '^' character, and when I try to return a std::string
, I can't compile it! 我想我返回了错误的类型(String ^),但我在'^'字符上找不到任何内容,当我尝试返回一个
std::string
,我无法编译它! Can someone help me? 有人能帮我吗?
String^
is "Reference to a GC object" - an object that exists in the Managed Heap (ie a ".NET object"). String^
是“引用GC对象” - 存在于Managed Heap中的对象(即“.NET对象”)。 Compared to String*
(a pointer to a System::String
CLR object or std::string
(a C++ standard-library string local). 与
String*
(指向System::String
CLR对象或std::string
(C ++标准库字符串本地)的指针相比)。
The C++ STL cout
stream does not support outputting System::String
, you must either first marshal it to a compatible type, or use Console::WriteLine
instead. C ++ STL
cout
流不支持输出System::String
,您必须首先将其封送到兼容类型,或者使用Console::WriteLine
。
To re-iterate what sp2danny said in the comments, this is not C++, this is C++/CLI, which can be considered a C++-esque syntax for CIL+CLR alternative to C# with the benefit of being able to use existing C++ code in source-form, including the STL. 要重新迭代sp2danny在评论中所说的内容,这不是 C ++,这是C ++ / CLI,它可以被认为是C ++ + C语言替代C#的C语言,有利于能够使用现有的C ++代码源形式,包括STL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.