156 Posted Topics
Re: You can look all that info up in a STL List reference, as the one found here: [url]http://www.cplusplus.com/reference/stl/list/[/url] See the "STL Algorithms" for sorting data inside STL containers. | |
My goal is to create a program that plays Mahjong. I figured the algo would be a bit like this: [code] While there are blocks left { Fetch new board Recognize blocks //find 2 of the same images within the image. Find free blocks //not *really* necessary: computer versions don't … | |
Re: So, what doesn't work? edges.open(); ? Double check the filepath please, hehe. Code looks okay, you won't need to clear it, unless errors occurred and you've recovered from them (or just want to reset them of course). | |
Re: [quote=halfnode]is it possible to put a constructor into an array?[/quote] Yes, take a look here for an example: [url]http://www.daniweb.com/forums/post847675-7.html[/url] The size specifier for the array (base* [[b]3[/b]]) is not necessary, but it will make sure the array is of size 3 of course. | |
Re: Header files such as string need to be included in the header file and in the .cpp file. We call these 2 files (header and .cpp) the definition of a class and its implementation when used to form a class. If you want more help, ask more questions, but try … | |
Re: [code=cpp] while(!inFile.eof()) { // use getline to read entire line getline(inFile, s); cout << s << endl; }[/code] That's wrong code. eof gets set when it has read eof, so and in that case getline() won't do a thing, so you'll output the last output twice (possibly). Correct code: [code=cpp] … | |
Re: [code=cpp]class Client { public: string name; Menu order; int table_number; string type; double bill; Client(void) { name=""; table_number=0; type=""; bill=0.0; } }; [/code] This code lacks the virtual addClient table wants to use. Another note: is a table a client? If not, you shouldn't have inheritance, but perhaps composition. | |
Re: No, [code=c] if(*n == ' '); [/code] | |
Re: So this should not be in a loop? [code=cpp] for (char *p = a; p!= fixPtr; p++) { *p=toupper(*p); }[/code] Why not do something like: [code] Set first letter to uppercase. Rest to lowercase [/code] with [code=c] void fixAddress ( char *a ) { a[0] = toupper(a[0]); for (int i … | |
Re: Oh hey look, it's free knowledge! [url]http://en.wikipedia.org/wiki/Sorting_algorithm[/url] | |
Re: So, you know what you have to do, do it. :) [code=cpp] class invoice { ... }; [/code] Something like that. | |
Re: [code=c] const int MAX = 13; int a[MAX]; for (int i = 0; i < MAX; ++i) a[i] = i; for (int i = 0; i < MAX; ++i) { int r = rand() % MAX; while(r == i) r = rand() % MAX; int t = a[i]; a[i] = … | |
Re: Hurr, it might be a really stupid "error". One time (at band camp, xD) I was trying to open a file from an app I wrote in Code::Blocks on windows. So I put that file in project/bin/debug/, but code::blocks launched it in project/, so it couldn't find the file. Try … | |
Hey guys, How do you handle exceptions in your programs? For instance, I have this function: [code=cpp]bool load_file(const char *filepath, std::string &dest) throw (std::bad_alloc, std::runtime_error) { using namespace std; ifstream file; file.open(filepath, ios::binary); if (!file.good()) { throw runtime_error("Couldn't open the file"); } //get filesize in bytes from ifstream //seek end, … | |
Re: If you're standing in queue line at the grocery shop, does the LINE look like a tree, with intersections and such, or more like an array of (possibly annoyed) customers? I sure hope it doesn't look like a tree. | |
Re: So, what doesn't work? Check here for more info on templates: [url]http://www.cplusplus.com/doc/tutorial/templates/[/url] | |
Re: Give it a shot here: [url]http://www.cplusplus.com/doc/tutorial/[/url] When you're stuck on a tutorial, you can ask for help of course. | |
Re: [quote=MrSpigot]main() is just reading it, so no protection is necessary in this case.[/quote] That's wrong, almost 100% sure, couldn't make sure with google, but it's just 2 threads trying to access the same memory: doesn't matter if they read or write, both will lead to errors. Agreed on not using … | |
Re: It's a slash in (/code), not a backslash. But A for effort. :D And you can supply the language as well, (code=cpp) Your code looks okay, but it looks a lot like C: it's not using OOP. Which would be a nice approach for a board game. My output looks … | |
Re: [URL="http://nsis.sourceforge.net/Main_Page"]Nullsoft installer[/URL]. Kicks ass! | |
Re: If your coding C, why post in the C++ forum? Anyway, show some code. A quick google gives me this: [url]http://weseetips.com/2008/08/27/how-to-set-color-for-static-control-text-in-dialog/[/url] and [url]http://www.programmersheaven.com/mb/mfc_coding/147975/147975/how-do-you-change-static-text-box-text-color/?S=B20000[/url] Don't know if they are addressing your problem. | |
Re: What doesn't work? new doesn't set the allocated memory to 0, could that be a problem? Be a bit more specific please. | |
Re: char *file? If you're using fgets(), I'm guessing it wants a C-style FILE *. ;) Anyway, you're in C++ land now, try getline() or something like that. Safer, easier. Other then that, the code is kinda.. bad.. You've a loop that fetches data from the ifstream into your char array, … | |
Hey guys, How do I disable/get rid of that default exception message windows shows when you have an "unhandled" exception in your program? Here's my example code (sorry for not limiting the code's size to the problem only, it's readable enough I think): [code=cpp] #include <iostream> #include <fstream> #include <string> … | |
Re: Create an array/vector of the struct (or pointers to), iterate it, compare the member variables to what you are looking for. | |
Hey guys, I've this code: [code=cpp] #include <iostream> #include <fstream> #include <sstream> #include <string> using namespace std; bool load_file(const string &filepath, string &dest){ ifstream file; file.open(filepath.c_str(), ios::binary); if(!file.good()){ cerr << "Fatal error while opening file." << endl; return false; } //get filesize in bytes from ifstream //seek end, get pointer, … | |
Re: Well lionleo, welcome to Daniweb: where we don't code homework assignments for others. :D What's the problem? Do you know how to read in a file? Grab lines from that file? Parse those lines? | |
Re: [code=cpp]void Employee::set(double payRate, int hours) { cin >> payRate; cin >> hours; }[/code] Change that to... [code=cpp]void Employee::set(double payRate, int hours) { this->payRate = payRate; this->hours = hours; }[/code] I'm not guarranteeing that it works on every compiler, but I think it should. If you don't understand the code, let … | |
Re: This is not C, I have no clue what language this is, sorry. |
The End.