简体   繁体   English

C ++ wxwidgets比较wxstrings

[英]C++ wxwidgets comparing wxstrings

I am trying to compare wxstrings to determine what my program will do. 我正在尝试比较wxstrings以确定我的程序将要执行的操作。 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. 我正在使用激活了wxSmith的代码块。

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). 单击该按钮后,脚本应该运行,因为它使用cdde命令(linux / ubuntu cli程序)生成了一个文件。 The result of this command is "An audio cd was inserted." 该命令的结果是“已插入音频CD”。 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). 在wxString中,<<将字符串附加到现有值上(类似于+会执行的操作,但如果需要,可以进行方便的类型转换)。 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. 您的函数ripmusicdvdmanip永远不会被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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