如何使用c++形式的文本框
How to use TextBox text in c++ form?
我想知道是否有人知道我如何将c++ windowsform
中的textbox
文本分配给字符串?
在c#中,就像这样:
string name;
name=textbox1.Text;
但是在c++中我不知道它是如何工作的。我试过了:
string name;
name = name_2door_txt->Text;
IntelliSense: no operator "=" matches these operands
operand types are: std::string = System::String ^
我需要它是一个字符串。你能帮帮我吗?
请包含以下头文件
#include <msclrmarshal_cppstd.h>
然后试着
msclr::interop::marshal_context context;
std::string std_string= context.marshal_as<std::string>(name_2door_txt->Text);
如果要转换为托管字符串
System::String^ managed_string = name_2door_txt->Text;
在system::string的参考中可以找到一些转换函数。例如,有toCharArray()函数。你可以这样做:
std::string name(name_2door_txt->Text.toCharArray());
裁判:https://msdn.microsoft.com/en-us/library/vstudio/system.string (v = vs.100) . aspx
试试这个:你需要为一个System::String
对象创建一个句柄(^
)
System::String^ name = name_2door_txt->Text;
改成:
System::String^ name;
name = textbox1->Text; // VisualC++
将名称传递给本机/非托管c++
using namespace System::Runtime::InteropServices;
std::string nName = static_cast<const char*>( Marshal::StringToHGlobalAnsi(name).ToPointer() );
callNative( nName ); // Call to C++ native
相关文章:
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 如何使用 GTK 3 正确设置默认文本
- 如何使用文件中的文本,例如变量
- C++ 使用存储在动态数组中的文本文件中的数据查找模式
- 有没有办法使用 c++ 实时阅读文本?
- 我无法在Visual Studio代码中使用CIN输入答案,它说输入您的年龄,但它说只读文本编辑器如何解决这个问题?
- 使用 Gtkmm 以编程方式选择 Gtk::TextView 中的文本
- 文本 RPG - 使用函数检查有效的输入
- 如何在C++中为整个文本文件使用字符串流while循环逻辑
- 是否可以在多行字符串文本中使用 C/C++ 预处理器令牌
- 如何在文本文件中仅读取一行,该文本文件使用QT具有特定单词
- CMD窗口停止工作,文本文件使用fstream读取错误
- 在字符串文本中使用制表符是否"bad practice"?
- OpenCV,在显示图像时读取用户文本输入(使用 waitKey)
- 占位符文本 文本字段中的文本在使用输入掩码时不显示
- 对cout或文本文件使用C++流
- c++程序在Xcode不输出简单的文本文件使用outFile
- 有没有办法在阅读文本时使用右移来识别'n'
- 我想计算总的和平均数据从文本文件使用c++
- Qt -文本框使用什么