我得到了这个使用文本的声明,但是我需要让它只适用于带有(,)小数的数字,现在我被卡住了……
public ref class Form1 : public System::Windows::Forms::Form
{
private: Stack<String^>^ talen;
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
talen = gcnew Stack<String^>();
}‘
private: System::Void btnPush_Click(System::Object^ sender, System::EventArgs^ e) {
String^ tal = tbxTal->Text;
talen->Push(tal);
tbxIn->AppendText(tal + "\n");
tbxTal->Text = "";
}
private: System::Void Pop_Click(System::Object^ sender, System::EventArgs^ e) {
while (talen->Count!=0)
{
String^ tal = talen->Pop();
tbxUt->AppendText(tal + "\n");
}
}发布于 2013-11-08 02:16:16
为了检查字符串是否包含有效的数字,我将使用可用的TryParse方法之一。
也许在Int32::TryParse中也是这样的。当然,您可以使用Single::TryParse、UInt16::TryParse来表示您喜欢的任何类型的数字。
int value;
String^ tal = tbxTal->Text;
if(Int32::TryParse(tal, value))
{
tbxIn->AppendText(tal + "\n");
tbxTal->Text = "";
talen->Push(tal);
}
else
{
// Show an error.
}如果您对堆栈所做的唯一事情就是您在Pop_Click中所显示的内容,那么Stack<String^>^是可以的,但是如果您正在使用它做其他事情,请考虑使用Stack<int>^ (或您选择的任何数据类型)。
https://stackoverflow.com/questions/19832151
复制相似问题