从 C++ 中的 wxTextCtrl 获取条目文本
Get entry text from wxTextCtrl in C++
我有这段代码:
void stoiximanFrame::OnButton1Click(wxCommandEvent& event)
{
cout<< TextCtrl1.GetValue() <<endl;
}
我只想从 TextCtrl1 获取文本,但出现此错误:
stoiximanFrame::TextCtrl1’, which is of pointer type ‘wxTextCtrl*’ (maybe you meant to use ‘->’ ?)
我是 C++ 的新手,所以我以前从未使用过指针。我已经阅读了指针的基础知识,但仍然无法弄清楚如何解决上述问题。
此外,如果有任何关于如何以及何时使用指针的好文档,我将不胜感激。
谢谢。
TextCtrl1
似乎是指向 class wxTextCtrl
(也就是 wxTextCtrl*
)对象的指针。通过使用箭头运算符 ->
,您可以访问指针指向的对象的 public 成员。它是使用解引用(*
)和成员访问(.
)的快捷方式。
这意味着 TextCtrl1->GetValue()
等同于 (*TextCtrl1).GetValue()
所以只要按照你的编译器说的写就可以了
cout << TextCtrl1->GetValue() << endl;
解决您的问题。
如果您是 C++ 的新手,我建议您阅读有关指针的内容。例如 here 因为这是与其他语言的主要区别之一。
我有这段代码:
void stoiximanFrame::OnButton1Click(wxCommandEvent& event)
{
cout<< TextCtrl1.GetValue() <<endl;
}
我只想从 TextCtrl1 获取文本,但出现此错误:
stoiximanFrame::TextCtrl1’, which is of pointer type ‘wxTextCtrl*’ (maybe you meant to use ‘->’ ?)
我是 C++ 的新手,所以我以前从未使用过指针。我已经阅读了指针的基础知识,但仍然无法弄清楚如何解决上述问题。
此外,如果有任何关于如何以及何时使用指针的好文档,我将不胜感激。
谢谢。
TextCtrl1
似乎是指向 class wxTextCtrl
(也就是 wxTextCtrl*
)对象的指针。通过使用箭头运算符 ->
,您可以访问指针指向的对象的 public 成员。它是使用解引用(*
)和成员访问(.
)的快捷方式。
这意味着 TextCtrl1->GetValue()
等同于 (*TextCtrl1).GetValue()
所以只要按照你的编译器说的写就可以了
cout << TextCtrl1->GetValue() << endl;
解决您的问题。
如果您是 C++ 的新手,我建议您阅读有关指针的内容。例如 here 因为这是与其他语言的主要区别之一。