Page 1 of 1

need help with wxwidget code

Posted: Tue Nov 22, 2011 5:44 am
by jloxy
hi i need help with this code, i dont know what it does. Please somebody explain what each line does so i can rewrite it to suit other similar functions

Code: Select all

void MyFrame::CreateBST(wxCommandEvent& WXUNUSED(event))
	{
		string word;
		wxString wxWord;
		
        	// Clear the edit box
        	MainEditBox->Clear();

		//open the file
		ifstream infile( CurrentDocPath.mb_str(), ios::in);		// ".mb_str()" gets the "string" from "wxString"

		while (!infile.eof())
			{		
				infile >> word;			// Get one word
//				word = strip(word);		// strip the word and lowercase it
				
				if ( (word.length() > 0) && (!infile.eof()) )
				{
				    //Insert the word into the BST
				    bst->insertNode(word);

				    //Display the word in the MainEditBox
				    wxWord = wxString(word.c_str(), wxConvUTF8);	// Convert word to proper wx format for appending
				    MainEditBox->AppendText( wxWord );			// Append the converted word
				    MainEditBox->AppendText( wxT("\n") );		// Change line after each word is appended		   
				}
				
			}

	}


Thank :)

EDIT by Auria : please use code tags

Re: need help with wxwidget code

Posted: Tue Nov 22, 2011 4:34 pm
by Auria
Sorry your question is very vague. I think this code is very explicit and well documented, apart maybe from "bst" but I assume from the larger context you can see what bst is.

So please more precise questions, explaining line by line what happens is pretty much already done since most lines are commented

Re: need help with wxwidget code

Posted: Tue Nov 22, 2011 7:49 pm
by jloxy
Ok I have to rewrite this code to use with a queue zoo I just done know what the code means , forgive me I am new to programming

Re: need help with wxwidget code

Posted: Tue Nov 22, 2011 10:34 pm
by Auria
This code reads a file and adds its content to an "Edit Box" and a "bst"

Re: need help with wxwidget code

Posted: Wed Nov 23, 2011 3:58 am
by jloxy
Ok so how would I write a "create queue " from this ?

Re: need help with wxwidget code

Posted: Wed Nov 23, 2011 3:51 pm
by Auria
jloxy wrote:Ok so how would I write a "create queue " from this ?
I'm sorry I don't understand what you are talking about. "Writing a create queue" does not seem to make much sense to me, and I don't see the link with the snippet posted

Re: need help with wxwidget code

Posted: Thu Nov 24, 2011 7:47 am
by DerKleineNik
Isn't that already some kinde of "create queue"?
It reads a number of words from the file and "creates" the EditBox text with that words one after the other.
Should you maybe rewrite that code using another kind of loop for example "for" instead of "while"?