显示在文本框中
display in textbox
我正在尝试学习如何在VS中使用Windows表单应用程序,但我发现了一个问题。我习惯于基于控制台的应用程序。所以问题是:
我有一个表单,我想在文本框中显示属于另一个类的函数结果,我想在按下按钮时执行此操作。例如,这是一个示例类:
#ifndef PRUEBA_H
#define PRUEBA_H
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
class Prueba
{
public:
void show()
{
cout<<"Thanks"<<endl;
}
};
#endif
这是按钮的代码:
#include "prueba.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Prueba *x = new Prueba();
textBox1->Text= System::Convert::ToString(x->show());
}
编译器给了我这个错误
error C2665: 'System::Convert::ToString' : none of the 37 overloads could convert all the argument types
任何人都可以提供帮助并发布在文本框中显示函数的正确方法吗?
void show()
{
cout<<"Thanks"<<endl;
}
此函数将一些文本打印到标准输出,但不返回任何内容。
你需要让它返回一个字符串。
您需要返回一个字符串,而不仅仅是打印到 stdout。像——
string show()
{
return "Thanks";
}
也代替
System::Convert::ToString(x->show());
你可能只需要
x->show();
就像其他人说的那样,您需要具有返回类型而不是打印到控制台中。
string show()
{
return "Thanks";
}
但是,您还想删除转换。
textBox1->Text = (x->show());
如果这仍然不起作用,那么我建议您尝试使用该函数设置另一个字符串,例如:
string v = x->show();
textBox1->Text = v;
并查看编译器出错的地方。
我终于得到了解决方案
#include <msclrmarshal.h>
#include <msclrmarshal_cppstd.h>
String^ s
s = marshal_as<String^>( what you want to put in the textbox );
textBox->Text += s + Environment::NewLine;
相关文章:
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 在由Sublime文本3编译后在cmd上显示Java程序输出
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 动态填充的组合框不显示文本,列表未定义
- 使用 fltk 时,文本未显示在已编译的窗口中
- PyQT - 在 QTableWidget 单元格中显示垂直文本
- 如何使用IExecuteCommand和动词在上下文菜单外壳扩展中显示本地化文本和自定义图标?
- 如何在 qt c++ 中更新 QWindow,文本不显示
- 从文本文件中读取并输入到数组结构中,然后显示读取的数据C++
- sf::文本不显示?
- 在QT C++编辑Qtable模型数据时,我需要得到一个小盒子,我需要显示编辑文本,这怎么可能?
- QTreeWidgetItem 突出显示文本问题
- 从文本文件中读取数据并删除所有换行符空格,并在 C++ 控制台中显示
- 如何通过单击按钮在QTextEdit中显示文本?
- 在C Windows程序中显示文本文件内容
- 如何在重新调整窗口大小时使文本显示在窗口中心,visualc++
- 打开 GL 文本显示时未处理的异常
- 如何要求输入后的文本显示下一行在c++中
- 如何将文件的路径(或任何文本)显示/附加到编辑框中?(C++ Win32 API)
- 将格式化文本显示到 QTextEdit 就像在 C 的 printf 中一样