简体   繁体   中英

Get entry text from wxTextCtrl in C++

I have this piece of code:

void stoiximanFrame::OnButton1Click(wxCommandEvent& event)
{
    cout<< TextCtrl1.GetValue() <<endl;

}

I just want to get the text from TextCtrl1 and I get this error:

stoiximanFrame::TextCtrl1', which is of pointer type 'wxTextCtrl*' (maybe you meant to use '->' ?)

I'm new to C++ so I've never used pointers before. I've read the basics of pointers but still I couldn't figure out how to solve the problem above.

In addition, I would appreciate any good documentation about how and when to use pointers.

Thanks.

TextCtrl1 seems to be a pointer to an object of class wxTextCtrl (also wxTextCtrl* ). By using the arrow operator -> you access the public members of the object the pointer is pointing to. It is a shortcut for using dereferencation( * ) and member access( . ).

This means TextCtrl1->GetValue() is equivalent to (*TextCtrl1).GetValue()

So just do what your compiler says and write

cout << TextCtrl1->GetValue() << endl;

to solve your problem.

If you are new to C++ i recommend you to read about pointers. For example here because that's one of the major differences to other languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM