147 Posted Topics
Re: It's impossible to pass a C array by value (see why [here](http://stackoverflow.com/questions/7454990/why-cant-we-pass-arrays-to-function-by-value)). If you want a function that can handle 2x2 and 3x3 and, in general, MxN arrays, you could use a function template. #include <iostream> using namespace std; void print2x2(int array[2][2]) { for (int i = 0; i < … | |
Re: Don't forget to get the debug privilege before opening a process other than your own. [Useful link](http://www.daniweb.com/software-development/cpp/threads/372173/how-do-i-search-for-a-memory-address-containing-a-specific-value-). Also, don't forget to close your handles once you're done (I forgot to do it...). [Another useful link](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx). | |
Re: [Here](http://zetcode.com/tutorials/javaswingtutorial/swinglayoutmanagement/)'s another good link. My personal favourite is the Box Layout: import java.awt.Dimension; import java.awt.Font; import javax.swing.*; public class Main extends JFrame { void init() { // we'll use a main panel and four row-panels JPanel basicPanel = new JPanel(); basicPanel.setLayout( new BoxLayout(basicPanel, BoxLayout.Y_AXIS)); JPanel titleRow = new JPanel(); titleRow.setLayout( … | |
Re: Oh, come on, guys, don't be so harsh. Let's help him get started... You could use two big sized arrays to represent your stacks. You'll have to also use two integers (initialized to zero) to keep track of each stack's current size. When you want to add a number to … | |
![]() | Re: What if you cast **rnd2** to an int? `ques.setText(questions[(int) rnd2]);` Note that you don't really need **Math.ceil** here. You could just do... `ques.setText(questions[(int) (Math.random() * questions.length)]);` |
Re: Obviously, this... for(int i = 0; i > nrEle ; i++){ for(int j = 0; j > nrEle; j++){ should be... for(int i = 0; i < nrEle ; i++){ for(int j = 0; j < nrEle; j++){ | |
Re: If you have to code this yourself, one way to do it would be to use the [inverse transformation](http://en.wikipedia.org/wiki/Inverse_transform_sampling) and [acceptance-rejection](http://en.wikipedia.org/wiki/Rejection_sampling) methods. I had to simulate normal distribution a while ago and that's how I did it: #include <iostream> #include <algorithm> #include <vector> #include <cstdlib> #include <ctime> #include <cmath> using … | |
Re: >I have a vector of doubles and I need to [...] write the contents to a **text** file. What's wrong with simply opening the file in text mode, iterating through your vector and outputing each double? **main.cpp** #include <iostream> #include <fstream> #include <vector> using namespace std; int main() { vector<double> … | |
Re: > I'm not sure how I would check if the values are 'parse-able' or not You could use a stringstream for that. First, get rid of the trailing whitespace characters in your input. Then, create a stringstream out of your input and use it to set your variable's value. If … | |
Re: You really should google more before posting. Look, I found a [thread](http://www.dreamincode.net/forums/topic/205131-about-bar-chart/) with a guy having the exact same code and a very similar problem to the one you're having. Considering the degree of similarity, I believe the replies he got should also be applicable to your case. | |
Re: > [...] The second should accept two arguments of type string (not C-string types) [...] Why do you use C-strings in your code then? > [...] Intuitively I would think template in C++ [...] You're right. Your maximum function template works fine for both doubles and std::strings. Also, as nullptr … | |
Re: It didn't work because you did something like this: while (numbersList >> type >> num1 >> num2) // you read a line here { Complex *object = new Complex(type,num1,num2); numbersList >> type >> num1 >> num2; // and then you read another line here cout << "For line number " … | |
Re: If you want to restrict input to integers in [1, 5], your while condition should be different. One way to do it is by using two relational operators and the logical OR operator. | |
Re: What if you make your get functions return references? vector<string> & getcoursename() {return coursename;} vector<double> & getmark() {return mark;} | |
Re: Actually, this is one of the things the OP, surprisingly, did right. I'm saying "surprisingly" because this is a very common mistake among beginners. Assuming... [CODE]string word; ifstream file("in.txt"); // in.txt contains a list of words[/CODE] ...what most beginners do when reading that file is this: [CODE]while (!file.fail()) { file … | |
Re: Geia sou Giannakh :D Kalws hr8es sto daniweb! Einai polu wraio na vlepw atoma apo thn patrida edw :) (translation ->) Hello, John :D Welcome to daniweb! It's very nice to see people from home here :) | |
Re: I have a couple of things to say regarding the base choice. In general, you'll want your base to be as big as possible, because this implies faster operations. However, there are other factors you should also consider, such as potential overflow during operations and conversion time from and to … | |
Re: Without optimizations, I get: [ICODE]0.078 seconds. 0.047 seconds.[/ICODE] With -O3 (best speed optimization) and after setting [ICODE]numberOfIterations[/ICODE] to [ICODE]1e9[/ICODE], I get: [ICODE]0 seconds. 3.297 seconds.[/ICODE] I use the version of mingw that comes along with the latest Code::Blocks. | |
Re: It shouldn't be too difficult. You could either create another function to display the polynomial or add a couple of cout statements in your current function. In either case, you'll probably need two for loops, an outer one that will iterate over f(x0), f[x0, x1], ..., f[x0, ... xn] and … | |
Re: Why do you want to specify the template parameters explicitly? I'm not really sure I understood what you want, so I'll just list a couple of things hoping one or two of them suits your needs. [CODE]#include <iostream> #include <vector> template <class T> class Simple { }; template <class T> … | |
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() … |
The End.