如何在 C++ 形式中使用 TextBox 文本? [英] How to use TextBox text in c++ form?
本文介绍了如何在 C++ 形式中使用 TextBox 文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有人知道如何将 C++ windowsform
中的 textbox
文本分配给字符串?
在 C# 中,例如:
I want to know is there anyone that knows how I can assign textbox
text in C++ windowsform
to a string?
In c# it's like for example:
string name;
name=textbox1.Text;
但在 C++ 中我不知道它是如何工作的.我试过这个:
but in C++ I don't know how it works. I've tried this:
string name;
name = name_2door_txt->Text;
但视觉给我这个错误:
IntelliSense: no operator "=" matches these operands
operand types are: std::string = System::String ^
我需要它是一个字符串.你能帮忙吗?
and I need it to be a string. Could you please help?
推荐答案
请包含以下头文件
#include <msclr\marshal_cppstd.h>
然后试试
msclr::interop::marshal_context context;
std::string std_string= context.marshal_as<std::string>(name_2door_txt->Text);
如果要转换为托管字符串
If you want to convert to managed string
System::String^ managed_string = name_2door_txt->Text;
这篇关于如何在 C++ 形式中使用 TextBox 文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文