简体   繁体   中英

C++ wxWidgets application not compiling

I am having a problem compiling my wxWidgets program.

#include <wx/wx.h>
#include <wx/url.h>
#include <wx/stream.h>
#include <wx/sstream.h>

int main(int argc, char* argv[])
{
    wxURL url(wxT("http://google.com"));
    if (url.GetError()==wxURL_NOERR)
    {
        wxString htmldata;
        wxInputStream *in = url.GetInputStream();
        if (in && in->IsOk())
        {
            wxStringOutputStream html_stream(&htmldata);
            in->Read(html_stream);
        }
        wxPuts(html_stream.GetString();
    }


}

When I try to compile it, I get the following errors:

main.cpp  In function 'int main(int, char**)':
main.cpp 8 error: 'wxURL' was not declared in this scope
main.cpp 8 error: expected ';' before 'url'
main.cpp 9 error: 'url' was not declared in this scope
main.cpp 9 error: 'wxURL_NOERR' was not declared in this scope
main.cpp 12 error: 'wxInputStream' was not declared in this scope
main.cpp 12 error: 'in' was not declared in this scope
main.cpp 15 error: 'wxStringOutputStream' was not declared in this scope
main.cpp 15 error: expected ';' before 'html_stream'
main.cpp 16 error: 'html_stream' was not declared in this scope
main.cpp 18 error: 'html_stream' was not declared in this scope
=== Build finished: 10 errors, 0 warnings ===

What am I doing wrong? Should I be using OnInit() instead of int main(), even if I want the application to be a console, non-gui one?

Take a look into your setup.h file for wxWidgets and be sure that wxURL is #define as

#define wxUSE_URL 1

For more information into your setup file (setup.h), take a look at http://wiki.wxwidgets.org/Setup.H

To take a look at a sample of wxURL, take a look into the your wxWidgets folder, go to "samples" and look into "sockets_client".

There is also reference documents at

http://docs.wxwidgets.org/2.9.3/classwx_u_r_i.html

http://wiki.wxwidgets.org/WxURL

http://wiki.wxwidgets.org/Download_a_file_from_internet

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