简体   繁体   中英

C++ wxwidgets comparing wxstrings

I am trying to compare wxstrings to determine what my program will do. The string I am comparing is based on a file I am reading in and is the only line in the file.

I am using codeblocks with wxSmith activated.

This is the section of my program that I am trying to get working.

void Disc_MasterFrame::OncdiscClick(wxCommandEvent& event)
{
    system("sh detect-disc.sh");

    wxString file;
    file << wxT("detect-disc");
    wxTextFile tfile;
    tfile.Open(file);
    detectdiscw=tfile.GetFirstLine();

    //std::ifstream myfile ("detect-disc");
    //getline (myfile,detectdisc);
    //myfile.close();

    cd << wxT("An audio cd was inserted.");
    dvd << wxT("A dvd was inserted.");

    if (detectdiscw == cd){
        //musicrip->Show();
        //this->Disc_MasterFrame::ripmusic();
        void ripmusic();
    }
    else if (detectdiscw == dvd)
    {
        manipdvd->Show();
        void dvdmanip();
    }
}

void Disc_MasterFrame::ripmusic()
{
    musicrip->Show();
    system("sh disc-info.sh");
    ...

When the button is clicked, the script should run, it does because it generates a file using the cdde command (linux/ubuntu cli program). The result of this command is "An audio cd was inserted." so I have consistency when testing.

Then it opens and reads the file and attempts to compare it to two predefined strings. Once that is done it should 'show' one of two panels already created.

I pretty sure I'm doing something wrong because it just sits there after the button is clicked.

Any help or direction would be greatly appreciated, thanks.

In a wxString, the << is appending a string to the existing value (similar to what + would do but with a handy type conversion if needed). I am not sure this is what you actually want to do. If you want to assign a new value to your string, then you should replace the << with =

The problem lies within your lines

void ripmusic();

and

void dvdmanip();

You intend to call these functions, but those are function declarations , not function calls. In other words, they do nothing. Your functions ripmusic and dvdmanip are never called.

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