I was wondering if anyone knows of any good gui tutorials for c++.
On another topic, what would be a good method to search a text document for text (I am writing a simple translator for my friend's language that he is using for his book).
I personally like wxWidgets for C++ GUI work (or python), but I don't know of any online tutorials for it as I just bought the official book on it (you'll have to google for some)
I then use DialogBlocks as my RAD (very stable, lots of features, and it will even create skeleton functions for any events you wish to process)
As for searching for text in a text document, you have two solutions. 1) if you know its a small document, just read the entire thing into a string and do a find on it. 2) Otherwise, go line by line and search
Code: #include <string>
#include <fstream>
using namespace std;
//other stuff here :)
string line;
string searchfor = "search for ME!";
ifstream infile("file_to_search");
if (!infile.is_open()) {
//print an error and exit
}
int index = -1;
while (!infile.eof() || (index == -1)) {
getline(infile, line);
index = line.find(searchfor);
}
cout << "Found [" << searchfor << "] at pos " << index << endl;
Note: I didn't really test that all too well - but you should be able to figure it out
Kllrnohj wrote:
I personally like wxWidgets for C++ GUI work (or python), but I don't know of any online tutorials for it as I just bought the official book on it (you'll have to google for some)
I then use DialogBlocks as my RAD (very stable, lots of features, and it will even create skeleton functions for any events you wish to process)
As for searching for text in a text document, you have two solutions. 1) if you know its a small document, just read the entire thing into a string and do a find on it. 2) Otherwise, go line by line and search
Code: #include <string>
#include <fstream>
using namespace std;
//other stuff here :)
string line;
string searchfor = "search for ME!";
ifstream infile("file_to_search");
if (!infile.is_open()) {
//print an error and exit
}
int index = -1;
while (!infile.eof() || (index == -1)) {
getline(infile, line);
index = line.find(searchfor);
}
cout << "Found [" << searchfor << "] at pos " << index << endl;
Note: I didn't really test that all too well - but you should be able to figure it out
Ok, thanks! =D I will try that.
I checked out a good book on Windows GUI programming with a focus on game programming called Beginning Game Programming by Michael Morrison. If you google it you'll find a few chapters online. The book contains much more and a CD with code, extra tutorials, and bonus games.
something1990 wrote:
I checked out a good book on Windows GUI programming with a focus on game programming called Beginning Game Programming by Michael Morrison. If you google it you'll find a few chapters online. The book contains much more and a CD with code, extra tutorials, and bonus games.
I will see if I can get that out of the libray . Right now I am just going to finish my translator and then when I get around to GUI I will clean it up and make it look perty .
something1990 wrote:
I checked out a good book on Windows GUI programming with a focus on game programming called Beginning Game Programming by Michael Morrison. If you google it you'll find a few chapters online. The book contains much more and a CD with code, extra tutorials, and bonus games.
I *think* I've seen that book, but its not so much GUI programming as just getting a window and drawing on it. It would be a pain in the butt to recreate all the controls you need, when there are already GUI APIs and toolkits to do that for you. So I would have to disagree with the recomendation of that book
Kllrnohj wrote:
something1990 wrote:
I checked out a good book on Windows GUI programming with a focus on game programming called Beginning Game Programming by Michael Morrison. If you google it you'll find a few chapters online. The book contains much more and a CD with code, extra tutorials, and bonus games.
I *think* I've seen that book, but its not so much GUI programming as just getting a window and drawing on it. It would be a pain in the butt to recreate all the controls you need, when there are already GUI APIs and toolkits to do that for you. So I would have to disagree with the recomendation of that book
yeah, an premade one would probably be better for me. Also, Just from a quick google search, is a RAD a tool to help develop GUI API's (like it looked like DialogBlocks generated the code for you after you did some stuff with it, lol.
RAD == Rapid Application Development. Basically you drag and drop (well, DialogBlocks uses menus, but you get the idea) a GUI together, and it then does all the nasty stuff like generating the classes, placing the controls, setting any flags, and generating empty functions for any events you wish to intercept.
So instead of hand-coding and placing the controls (which can be kinda hard to visualize, lol), you can quickly design the GUI, and then just program all the events
All major GUI APIs have at least one RAD. Win32 and .NET have Visual Studio, wxWidgets has severl (dialogblocks, wxGlade, etc..), GTK and GTKMM (the c++ port of GTK) have Glade, and Qt has a couple aswell, although I'm not too familiar with them (only one I know of is KDevelop)
Kllrnohj wrote:
something1990 wrote:
I checked out a good book on Windows GUI programming with a focus on game programming called Beginning Game Programming by Michael Morrison. If you google it you'll find a few chapters online. The book contains much more and a CD with code, extra tutorials, and bonus games.
I *think* I've seen that book, but its not so much GUI programming as just getting a window and drawing on it. It would be a pain in the butt to recreate all the controls you need, when there are already GUI APIs and toolkits to do that for you. So I would have to disagree with the recomendation of that book
Ok, thanks for the info!
Anyways, I am pretty much done with the code except for the search part (might do that later or tommorrow, I do not know)
(I did a syntax check on it and the only error is I have not defined the search function)
Code:
/************************************************************
This is a translator for the language Nafforad. Although, *
by using a different text file it could be used for almost *
any language. It searches for the inputted text (+ a ' =' to*
make sure it finds one on the left side) and then returns *
the right text *
/************************************************************/
#include <iostream>
#include <string>
#include <fstream>
using namespace std; //initialize
#define TEXT_FILE Translations //defines which file to read translations from
void convert_to_lower(char *string) { //converts the input to lower case
int length = strlen(string);
for (int c = 0; c < length; c++) //loops through input
string[c] = tolower(string[c]);
}
int get_word(char *read_from, char *inv_word, int cur_pos) {
//parses entry into words
while (read_from[cur_pos] == ',' || read_from[cur_pos] == ' ')
// skips ,'s and spaces
cur_pos++;
if (read_from[cur_pos] == '\0') //returns -1 if at the end of the string
return -1;
int wo_pos = 0;
while (read_from[cur_pos] != ',' && read_from[cur_pos] != '\0' && read_from[cur_pos] != ' ') {
inv_word[wo_pos] = read_from[cur_pos];
wo_pos++;
cur_pos++;
}
inv_word[wo_pos + 1] = ' ';
inv_word[wo_pos + 2] = '=';
if (read_from[cur_pos] == '\0')
return -1; //returns -1 if at the end of entry
return cur_pos; // else returns the current position
}
int main() {
char repeat = 'y'; // repeat loop?
char entry[201]; //entry, up to 200 characters
char word[50]; // individual words in the entry
string result = " "; //the final result
int pos = 0;
while (repeat = 'y') { //keeps going until user does not type y
system("cls"); //clears screen
cout << "Please enter text that you want translated (up to 200 characters) :";
cin.getline(entry, 200); //gets entry
convert_to_lower(entry);
while (pos != -1) {
pos = get_word(entry, word, pos); //gets 1 word
result = result + search_trans(word); //DEFINE SEARCH_TRANS!
}
cout << "\n\n The translated version of that text is: " << result;
system("pause");
cout << "Again? (y to translate something else)";
cin >> repeat;
}
}
Ok - wtf? You are doing this in C++, but you are using C-strings? C-strings == BAD! C-strings are the source of all those buffer overflow exploits you hear about. Seriously, use the C++ Strings (which is, after all, the reason you are including string instead of string.h
)
Kllrnohj wrote:
Ok - wtf? You are doing this in C++, but you are using C-strings? C-strings == BAD! C-strings are the source of all those buffer overflow exploits you hear about. Seriously, use the C++ Strings (which is, after all, the reason you are including string instead of string.h
)
Let me put it this way... I am realllly bad at strings =D. I pretty much forgot all the c++ string commands and such .
It doesn't matter if you are "bad" at them or not, you still use them. Google for a class reference and re-learn!
K, I converted it to c++ strings (quickly, but I will debug more later).
Code: /************************************************************
This is a translator for the language Nafforad. Although, *
by using a different text file it could be used for almost *
any language. It searches for the inputted text (+ a ' =' to*
make sure it finds one on the left side) and then returns *
the right text *
/************************************************************/
#include <iostream>
#include <string>
#include <fstream>
using namespace std; //initialize
#define TEXT_FILE Translations //defines which file to read translations from
void convert_to_lower(string string) { //converts the input to lower case
int length = string.length();
for (int c = 0; c < length; c++) //loops through input
string[c] = tolower(string[c]);
}
int get_word(string read_from, string inv_word, int cur_pos) {
//parses entry into words
while (read_from[cur_pos] == ',' || read_from[cur_pos] == ' ')
// skips ,'s and spaces
cur_pos++;
if (cur_pos == read_from.length()) //returns -1 if at the end of the string
return -1;
int wo_pos = 0;
while (read_from.substr(cur_pos,1) != "," && cur_pos != read_from.length() && read_from.substr(cur_pos,1) != " ") {
inv_word[wo_pos] = read_from[cur_pos];
wo_pos++;
cur_pos++;
}
inv_word + " =";
if (cur_pos == read_from.length())
return -1; //returns -1 if at the end of entry
return cur_pos; // else returns the current position
}
int main() {
bool repeat = 1; // repeat loop?
string entry; //entry, up to 200 characters
string word; // individual words in the entry
string result; //the final result
int pos = 0;
while (repeat == 1) { //keeps going until user does not type y
pos = 0;
result = " ";
entry.empty();
system("cls"); //clears screen
cout << "Please enter text that you want translated (up to 200 characters) :";
getline(cin, entry); //gets entry
convert_to_lower(entry);
while (pos != -1) {
word = " ";
pos = get_word(entry, word, pos); //gets 1 word
cout << word << "\n\n";
//result = result + search_trans(word); //DEFINE SEARCH_TRANS!
}
cout << "\n\n The translated version of that text is: " << result;
system("pause");
cout << "Again? (1 for yes):";
cin >> repeat;
}
}
Oh yeah, don't c++ strings automatically pass as an address? Otherwise I need to change that.
Harq wrote:
Oh yeah, don't c++ strings automatically pass as an address? Otherwise I need to change that.
No, I don't think they do...
Kllrnohj wrote:
Harq wrote:
Oh yeah, don't c++ strings automatically pass as an address? Otherwise I need to change that.
No, I don't think they do... I'm almost sure that they don't, contrary to C-strings.
Yeah, because C++ strings are a class, not an array like C-strings
Kllrnohj wrote:
Yeah, because C++ strings are a class, not an array like C-strings
Isn't it still an array somewhere or other though?
I think he should also know about the
Win32 and COM Development Section of MSDN. It contains documentation on all the functions you would use in Windows programming as well as examples and minitutorials on some concepts of Win32 programming.
something1990 wrote:
I think he should also know about the
Win32 and COM Development Section of MSDN. It contains documentation on all the functions you would use in Windows programming as well as examples and minitutorials on some concepts of Win32 programming.
Don't use the MS crappy stuff. Their strings suck ballz, the STL pwns the MS ones (and the STL ones are standard and therefore won't break on other systems ) Besides, who said anything about Windows programming?
@Kerm: Of course it still stores it as a char array somewhere (you just can't modify it - it is available as a const char* via the string::c_string() function)
A readonly const (oh right, it's a const). Anyway, yeah, avoid MS-specific stuff like the plague. Crossplatform == good.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
»
Go to Registration page
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum