如何将字符串输出到列表框 [英] how can I output string to listbox

查看:113
本文介绍了如何将字符串输出到列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我实现了一个非常简单的表单,其中包含一个文本框和一个列表框,因此当我按下按钮时,它会将文本框添加到列表框;但是字符串变量不起作用,我得到了<错误C2065:字符串":未声明的标识符">

这是代码



guys, I have implemented a very simple form with a textbox and a listbox, so when I press on the button it adds the textbox to listbox; however the string variable its not working, I''m getting <error C2065: ''string'' : undeclared identifier>

here''s the code



private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    string host;
    host = textBox1->Text;
    listBox1->Items->Add(host);
    }




我想要实现的是能够对主机执行ping操作并将其输出到列表框...但是我陷入了这个问题




what I want to achieve is to be able to ping the host and output to listbox... but I''m stuck with this problem

推荐答案

您的特定问题是此:#include <string>.添加此行后,该类型可用,并且为std::string.如果在使用std类型之前也添加了using name space std;,则可以省略std::的完全限定.

您正在混合在一起:如何对主机执行ping操作等?您需要学习分离关注点.您需要学习辨别编译错误和运行时错误之间的区别(并正确报告错误)以及更多其他内容.
不幸的是,我不觉得您准备好使用C ++开发任何应用程序以及在CodeProject上提问.首先,您需要学习一些基础知识.

有关此主题,请参见:
Microsoft Q209354
http://norvig.com/21-days.html [我的程序有问题.请帮忙! [ 对于.NET,OP在下面的评论中发布了正确的答案.我只想补充一点,可以使用"using namespace System;"代替完全限定的"System::".两种方式都足够好.我坚持我对使用CodeProject和学习的看法不变.
OP还建议正确标记问题,以免造成误解.

—SA
You particular problem is this: #include <string>. After you add this line, the type is available and is std::string. You can omit full qualification with std:: if you also add using name space std; before using std types.

You''re mixing things together: what about pinging the host, etc.? You need to learn to separate concerns. You need to learn to tell the difference between compilation and run-time errors (and report them properly) and a lot more.
Unfortunately, I don''t feel your ready for development of any applications in C++, as well as asking questions at CodeProject. First, you need to learn some basics.

See on this topic:
Microsoft Q209354
http://norvig.com/21-days.html[^]
See also my instructions on reading manual and exercises: I have a problem with my program. Please help![^].

The Answer above is based or wrong Question tag "C++" (should be "C++/CLI").
For .NET, OP posted a correct answer in the comment below. I only would like to add that "using namespace System;" could be used instead of full qualification "System::". Both ways are good enough though. I insist my opinion about using CodeProject and learning remains the same.
OP also recommended to to tag Questions properly to avoid misunderstanding.

—SA


这篇关于如何将字符串输出到列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆