147 Posted Topics
Re: Another reason might be that your program can't find SDL.dll and/or SDL_image.dll. The former comes along with SDL but the latter doesn't (AFAIK). You can get it from here -> [URL="http://www.libsdl.org/projects/SDL_image/"]SDL_image[/URL]. Copy these two dlls next to your exe and see if it works. EDIT: Hmmm... It looks like you'll … | |
Re: Okay. In this case, an [URL="http://www.boost.org/doc/libs/1_48_0/libs/iterator/doc/indirect_iterator.html"]indirect_iterator[/URL] is exactly what you need. | |
Re: Another option would be to use [URL="http://www.boost.org/doc/libs/1_48_0/libs/iterator/doc/index.html"]Boost.Iterator[/URL]. | |
![]() | Re: You don't have to call [ICODE]strlen[/ICODE] or any other function to compute your word's length. Notice that, inside your loop, [ICODE]c[/ICODE] represents the number of correct consecutive letters. Just add a bool variable outside your loop and modify it appropriately inside the loop: [CODE]bool found = false; while(true) { if … ![]() |
Re: Does anyone play DotA? What are your favourite heroes and item builds? | |
Re: [QUOTE=Narue]Show me yours and I'll show you mine.[/QUOTE] Am I the only one who keeps misinterpreting that? ![]() | |
Re: [QUOTE=Narue]I don't do graphics.[/QUOTE] Why not? Doing graphics can be so much fun! I do graphics all the time! :D Here's something I've been working on lately -> I saw this [URL="http://www.newgrounds.com/portal/view/578450"]flash game[/URL] where the sprite animations where created by applying a series of transformations (scalings, rotations, shearings, translations... etc) … | |
Re: What if you put two [ICODE]getchar[/ICODE] calls instead of one? | |
Re: [QUOTE=fibbo]I just would like some input/critics/heads up on my class definition and implementation I did for my project.[/QUOTE] Looks good. There are a couple of small issues, but other than that looks good. About the small issues now... Your [ICODE]m_vector[/ICODE] doesn't have to be a vector pointer. A vector object … | |
Re: You can find the functions you need here -> [URL="http://msdn.microsoft.com/en-us/library/ms682073(v=vs.85).aspx"]Windows Console Functions[/URL] Here, I wrapped them for you: [CODE]#include <windows.h> #include <iostream> void gotoxy(int x, int y) { COORD pos = { x, y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } int wherex() { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); return csbi.dwCursorPosition.X; } int wherey() … | |
Re: I know this is marked as solved, but I believe that the above example yields duplicate numbers, too. I think the OP is looking for a [URL="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle"]shuffling algorithm[/URL]. | |
Re: What's wrong with simply using the [I]address[/I] of [ICODE]m_type[/ICODE] as the unique ID you want? Here's an example -> [url]http://www.cplusplus.com/forum/general/33296/#msg179678[/url] | |
Re: ... you laugh with things like "Chuck Norris can dereference a void pointer." or "In Soviet Russia, functions call [B]you[/B]." | |
Re: While multithreading is indeed the way to go in such cases, I believe the OP might be able to get away with just a [ICODE]_kbhit[/ICODE] call. [CODE]#include <windows.h> #include <conio.h> #include <iostream> int main() { int counter = 0; char ch = 0; while (true) { ch = 0; if … | |
Re: [QUOTE=imstarting]I found a video course like that: [url]http://video-courses-online.com/programming-courses-online/c-course.php[/url][/QUOTE]Why pay for it when there are plenty free ones out there? Here's one of the few I find decent -> [URL="http://www.thenewboston.com/?cat=66&pOpen=tutorial"]decent C++ video tutorial[/URL] | |
Re: Ok, since nobody has replied yet, I thought I'd give it a shot. Warning -> I'm not an expert, at all. I just started learning python. The above statement prints 7, left zero padded, so that the total number of digits is 3. You can also put 3 in the … | |
Re: Yeah, I had a similar problem too when I started playing with SFML. The solution is simple, but I don't really understand how/why it works... The main problem is this here -> [ICODE]sf::Shape Rect2 = sf::Shape::Rectangle(50, 0, 70, 20, sf::Color::Blue);[/ICODE]. It should be -> [ICODE]sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 20, … | |
Re: [QUOTE=Narue]C++ does not allow nested functions either.[/QUOTE] Technically, true. But there are workarounds -> [URL="http://www.respower.com/~earlye/programming/19990916.001.htm"]nesting functions in C++[/URL] However, I'm quite sure that this is not what the OP is looking for... | |
Re: This isn't much of a challenge as it is now, so I decided to do the interesting stuff during compilation. EDIT: A boost preprocessor array can't have more than 25 elements. That's why I had to split the letters like that. [CODE]#include <boost/preprocessor/repetition/repeat.hpp> #include <boost/preprocessor/comparison/less.hpp> #include <boost/preprocessor/arithmetic/add.hpp> #include <boost/preprocessor/arithmetic/sub.hpp> #include … ![]() | |
Re: The problem is here -> [ICODE]if(i [COLOR="Red"]=[/COLOR] rhs.size - 1)[/ICODE]. It should be -> [ICODE]if(i [COLOR="Green"]==[/COLOR] rhs.size - 1)[/ICODE] | |
Re: Another good option is the ClipCursor function: [CODE]#include <windows.h> int main() { RECT old_rect; GetClipCursor(&old_rect); RECT new_rect = { 500, 500, 501, 501 }; ClipCursor(&new_rect); Sleep(2500); ClipCursor(&old_rect); return 0; }[/CODE] | |
Re: There are a couple of things that need to be fixed. (1) This is a problem -> [ICODE]p = (Translator*)malloc(sizeof(Translator));[/ICODE] because malloc doesn't call constructors. This means that the underlying string objects are not initialized properly (perhaps some internal pointers are not set?). Therefore, the program crashes when you try … | |
Re: And I need world peace. If you can give me that, I'll gladly give you a class of string. | |
Re: The problem is that you never create a [ICODE]cs_EnableOverrideAction[/ICODE] object in main. What you create in main is just an uninitialized pointer that could point to anything. This will work fine -> [ICODE]cs_EnableOverrideAction * enableit = new cs_EnableOverrideAction;[/ICODE] This would also work find -> [ICODE]cs_PureFunction * enableit = new cs_EnableOverrideAction;[/ICODE] … | |
Re: These -> [ICODE]15 32 50 32 15[/ICODE] are the coefficients of the polynomial you'd get if you multiplied the polynomials [ICODE]3*x^2 + 4*x + 5[/ICODE] and [ICODE]5*x^2 + 4*x + 3[/ICODE] together. Useful links -> [URL="http://en.wikipedia.org/wiki/Convolution#Discrete_convolution"]Discrete Convolution[/URL], [URL="http://en.wikipedia.org/wiki/Cauchy_product"]Cauchy Product[/URL] | |
Re: How about using virtual functions? [CODE]#include <iostream> using namespace std; struct A { virtual void print_me() const {} virtual ~A() {} }; struct B : A { void print_me() const { cout << "Hello, I'm B!" << endl; } }; struct C : A { void print_me() const { cout … | |
Re: It depends. If n denotes the number of rows (or columns - it's the same, since it doesn't make sense to check if a rectangular matrix is symmetric), then the above algorithm's complexity is O(n^2). But if n denotes the number of elements, then, yes, the above algorithm's complexity is … | |
Re: Can you tell us what you want to do with the array? We may be able to suggest a better solution. | |
Re: [QUOTE=dilequeno]I want to do the same thing with a 3D vector. How would the code look?[/QUOTE] You can do it like this: [CODE]vector<vector<vector<float> > > vec (5, vector<vector<float> > (5, vector<float> (5, 0) ) );[/CODE] The above creates a 5 x 5 x 5 3D vector, with all initial values … | |
Re: Note that you have to [ICODE]#define _WIN32_WINNT 0x0500[/ICODE] [B]before[/B] including windows.h in order to be able to use GetConsoleWindow. It says so in the remarks section of the relevant link posted above. | |
Re: And if you want to stick to the current standard, you can always use boost lambdas: [CODE]#include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> #include <algorithm> #include <iostream> #include <vector> #include <map> int main() { using namespace boost::lambda; std::vector<int> items(25); std::map<int, int> counts; for (int i = 0; i < 25; ++i) items[i] = … | |
Re: How about something less tricky. Something like this: [CODE]#include <windows.h> #include <iostream> #include <cmath> bool IsPressed(int vkey) { return GetAsyncKeyState(vkey) >> 15; } void MouseMove(int dx, int dy) { POINT point; GetCursorPos(&point); SetCursorPos(point.x + dx, point.y + dy); } const double slope_max = 1.35; const double slope_change = 0.15; const … | |
Re: I don't know what you mean by saying "hook", but if you want to hide the console cursor, you can do it like this: [CODE]#include <windows.h> #include <iostream> int main() { HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursor_info; GetConsoleCursorInfo(console, &cursor_info); cursor_info.bVisible = false; SetConsoleCursorInfo(console, &cursor_info); std::cout << "See? No cursor! -> … | |
Re: Can you show us the definition of CDocum::~CDocum and CDocum::QuoteDocProd? | |
Re: I will be very disappointed if this thread doesn't turn into a C vs C++ flamewar... | |
Re: The [ICODE]setw[/ICODE] manipulator has the same problem. It only affects the next output operation. AFAIK, there is no way you can avoid setting the width over and over again. Maybe someone else knows better though. Here's a simple hackish solution: [CODE]#include <iostream> #include <sstream> using namespace std; class ostream_w : … | |
Re: If you want to modify something inside a function, you should pass it by reference ;) This will work -> [ICODE]void change(float (*[B]&[/B]d)[3], float (*e)[3]) { d = e; }[/ICODE] | |
Re: As pseudorandom suggested, the first step would be to convert the integer to a string. Alternatively, if you want to skip that step, you could just get a string from the user. Now, let's take a look at the algorithm... Suppose the user enters this -> [ICODE]"1234567890"[/ICODE]. The result of … | |
Re: I'm pretty sure the statement updating your population should be -> [ICODE]population *= (1 + annualBirth - annualDeath);[/ICODE] | |
Re: Check this out: [CODE]#include <iostream> #include <cmath> using namespace std; int main() { double val_1 = 1.56356; double val_2 = 1.56756; cout << floor( (val_1 + 0.005) * 100.0 ) / 100.0 << endl; cout << floor( (val_2 + 0.005) * 100.0 ) / 100.0 << endl; return 0; }[/CODE] … | |
Re: You can use ReadProcessMemory: [CODE]#include <windows.h> #include <iostream> #include <cstring> using namespace std; int main() { char data[20] = "Hello, World!!!"; char buffer[20] = { 0 }; HANDLE my_process = GetCurrentProcess(); unsigned long address = 0; cout << "(before) " << data << endl; while (true) { ReadProcessMemory(my_process, (LPCVOID) address, … | |
Re: Are you sure the library doesn't exist in your MinGW folders? I have the latest version of Code::Blocks/MinGW and I was able to locate it here -> [ICODE]...CodeBlocks\MinGW\lib\libpsapi.a[/ICODE] See if you can find it, link to it and see if the problem persists. | |
Re: What if you try [ICODE]std::cout << [B]M_pGSLData->data[/B] + i*[B]M_pGSLData->tda[/B] + j << " ";[/ICODE] instead? | |
Re: [ICODE]map<uint16_t,set<float[U]>>[/U][/ICODE] <- This here means the OP uses Visual Studio ;) This should work -> [url]http://msdn.microsoft.com/en-us/library/0d462wfh(v=VS.90).aspx[/url] | |
Re: What do you mean when you say "special characters"? And what do you mean when you say "space"? Try this as your pattern -> [ICODE][^A-Za-z\\s0-9][/ICODE] ( '\s' means space, tab, newline etc... ) Useful link -> [url]http://download.oracle.com/javase/tutorial/essential/regex/[/url] | |
Re: Try this: [CODE]//... string = string.replace('\', '/'); // replace \ with / string = string.replace('\"', ' '); // replace " with space string = string.trim(); // remove leading and trailing spaces //...[/CODE] | |
Re: [CODE]//... if(n1 < n2) { cout << "You beat the high score of " << n1 << "." << endl; file.seekp(0, ios::beg); // move to the beginning of the file before writing file << n2 << endl; // I believe you want to write the new high score } //...[/CODE] | |
Re: Your program doesn't remove anything :P It just outputs the string omitting the first letter. E.g., entering this -> [B]aaabbbddccc[/B] will cause your program to output this -> [B]aabbbddccc[/B] Can you describe in english how you would remove duplicates from a string? If I give you this string -> [B]aaabbbddccc#[/B] … | |
Re: Two things you need to do: (1) Read the data from the file (put [ICODE]widgets >> d_...[/ICODE] statements first thing inside your for loop). (2) Print the data only after you get all of it (close your for loop immediately after closing [ICODE]if(!head)[/ICODE]). | |
Re: [QUOTE=gauravk_bhanot]when the base pointer points to derived object it prints i am derived[/QUOTE] This is exactly what it's supposed to do. Take a look at this: [CODE]#include <iostream> #include <vector> using namespace std; struct Fruit { virtual void Speak() {} virtual ~Fruit() {} }; struct Apple : Fruit { void … |
The End.