1,118 Posted Topics
Re: He didn't misunderstand. There are two ways to look at "inline": 1. the OP wants to avoid using function call syntax 2. AD's code actually avoids calling a function Either way the best solution takes multiple lines of code, as posted. | |
Re: You'll have to give an effort yourself first. You'll have to create a function that takes as argument a 2D vector: [inlinecode]void fillVectorOfVector( vector< vector<double> > &v )[/inlinecode] The code in [B]printVectorOfVector()[/B] should help you there. To generate random numbers see [URL="http://www.daniweb.com/forums/thread1769.html"]here[/URL]. Post again with what you come up with, … | |
Re: All user input is terminated by pressing the ENTER key. Users expect this. If you want to get individual key presses, you must do an OS-specific thing: disable buffered input. On Windows, use [URL="http://www.google.com/search?btnI=1&q=msdn+setconsolemode"][b]SetConsoleMode[/b]()[/URL]. On POSIX, use [URL="http://linux.die.net/man/3/tcsetattr"][b]tcsetattr[/b]()[/URL]. Be sure that you only do this when the user expects it, … | |
Re: You need to get a good Win32 reference. The function you want is [inlinecode]BOOL RemoveDirectory( LPCTSTR lpPathName );[/inlinecode] The directory must be empty and your program must have permissions to delete it. If the function fails it returns zero, else it returns non-zero. Hope this helps. | |
Re: There is nothing more or less hard about C++ than any other programming language. People fear C++ because it comes with a very [i]large[/i] set of capabilities. It can be used to program procedurally. It can be used to program object-orientedly. It can be used to program generically. It can … | |
Re: > On the plus side, being DOS, you can generate simple low-resolution graphics (which a true Win32 console cannot). Actually, if you get the DC of the console window, you can draw on it like any other. Unfortunately, it is impossible to use a window proc on the console window... … | |
Hi all. I have some questions that may cover multiple forums, but I think this is the most appropriate. I have been working on my wife's new website. You can see its current state here: [url]http://home.comcast.net/~mlyn7576/signandgrow/[/url] The following questions apply both to the home page and one of the sub-pages. … | |
Re: You need to read up at [URL="http://www.newty.de/fpt/"][b]The Function Pointer Tutorials[/b][/URL] Good luck! | |
Re: More explicitly, even though [inlinecode]int a[5];[/inlinecode] and [inlinecode]int *a;[/inlinecode] both declare [B]a[/B] to be a pointer to an integer, the first is [I]constant[/I], meaning that you cannot change the value of [B]a[/B] (it cannot be used as an lvalue). You will save yourself some accidental grief if you keep different … | |
Re: [color=green]You need to be just a little more careful with names[/color] [B]Insertion()[/B] is a bad name because it is not obvious that it sorts the list. [B]InsertionSort()[/B] is a good name. [B]Destroy()[/B] is not a good name because it doesn't destroy your object; it only deletes every item in the … | |
Re: You can't initialize it inside the class definition. Do this instead: [code=C++] class Test { public: static const string MYARRAY[]; }; const string Test::MYARRAY[] = {"hello", "world"}; [/code] Have fun! | |
Re: If I remember correctly the Foo tutorials instruct you to get the pre-compiled binary DLLs. It should have come with some header files. Did you put them in the include path? Did you tell VC++ where to find the lib files? Did you link with the SDL DLL? | |
Re: Please use [[B][/B]code] [[B][/B]/code] tags. It looks like you are off to a fairly good start, but you are missing a couple things. Remember, in Pascal multiple statements [I]must[/I] be enclosed in a [b]begin[/b]..[b]end[/b] block. Also, make sure you get a good reference. It looks to me like you are … | |
Re: This is the C++ forum, not the C forum. You cannot expect C answers in a C++ forum. Nevertheless, [b]AD[/b] [i]did[/i] answer your question sufficiently. The answer works the same way, except you use a FILE* instead of an istream. If you can use FILE*s, you can do it. Please … | |
Re: You've pretty much learned all there is to it: the STL streams library does not handle non-[b]binary[/b] streams very well. If you plan to [b]seek[/b][[b]g[/b]|[b]p[/b]]() / [b]tell[/b][[b]g[/b]|[b]p[/b]]() at all, use binary I/O. Sorry. | |
Re: What you want to do is an OS-specific function. What Operating System are you using? | |
Re: It is not entirely clear what you want to do, but if it is just copying specific elements of a container to another container, use the [b]remove_copy_if[/b]() STL algorithm, along with a predicate that decides what it is you wish to [i]not[/i] copy, and a [b]back_insert_iterator[/b]<> to stick the results … | |
Re: No exception is thrown when you enter bad input. Instead, the input stream is set to a [i]fail state[/i]. Check using the [b]good[/b]() member function. [code=C++] int n; cout << "Enter a number: " << flush; while (true) { cin >> n; if (!cin.good()) { cin.clear(); // clear the error … | |
Re: Your professor is a jerk. (Anyone who would instruct his students to do something before doing it himself [i]the same way students would[/i] is a jerk.) Using [inlinecode]system( "color 1B" );[/inlinecode] [i]doesn't work[/i] -- that modifies the color of the [i]entire console window[/i]. Since you are on Windows, there are … | |
Re: Whenever you get errors, it is typically a good idea go to the line with the error on it. On line 63 you have: [code=C++ firstline=63] cout<<"The paycheck for the salesperson will be approximately ">>payCheck>>" " [/code] The error message says it has a problem with '>>' on that line. … | |
Re: It has to do with what type of character input the [I]compiler[/I] expects and what kind of character data your [I]program[/I] expects. Surprisingly, the two may be different. Unfortunately, anything outside the ASCII range (0..127) is not safe to put in a string/character literal. Alas. | |
Re: The typical way to handle this is to create a hidden parent window for the whole application. All other top-level windows are children of this parent window, so no extra taskbar buttons are created for them. To quote the MS docs under [B]Visibility of Taskbar Buttons[/B] [quote]A taskbar button is … | |
Re: What you want to do is not something that is addressed by the C or C++ standards: you must use OS-specific code or special extensions. On Windows (which you are using if you are using Dev-C++), you should use the [URL="http://www.google.com/search?btnI=1&q=msdn+WaitForSingleObject"][b]WaitForSingleObject[/b]()[/URL] function. Use [URL="http://www.google.com/search?btnI=1&q=msdn+GetStdHandle"][b]GetStdHandle[/b]()[/URL] to get the first argument. You'll … | |
Re: You need to either run your program from the command prompt, or put some form of pause at the end of your program. For example: [code=C++] #include <iostream> #include <limits> using namespace std; int main() { // This is my program cout << "Hello world!\n\n\n"; // This keeps the console … | |
Re: [i]Don't[/i] use [b]strtok[/b](). It is for handling C-strings (not [b]std[/b]::[b]string[/b]s), and it modifies the string. Use the [b]find_first_of[/b]() and [b]substr[/b]() string member functions instead. Hope this helps. | |
Re: You need to specify the standard you are compiling against. The GCC defaults to using its own extensions. [inlinecode]g++ -Wall -ansi -pedantic ...[/inlinecode] Hope this helps. | |
Re: I've only used these things in [b]Delphi[/b], but it looks right to me. The only concern I have is based upon your error message: what kind of thing is [b]OpenDialog1[/b]? Is it a [i]pointer[/i] to a [b]TOpenDialog[/b]? (And not an direct object or a reference?) Is it [i]visible[/i] in the … | |
Re: The [b]BitBlt[/b]() function doesn't resize images. You need [URL="http://www.google.com/search?btnI=1&q=msdn+StretchBlt"][b]StretchBlt[/b]()[/URL]. It does a really bad job, btw, so it might be worth your while to use an external library to do image transformations. Hope this helps. | |
Re: He has [inlinecode]#include <windows.h>[/inlinecode], so I believe we can safely assume some things about his operating environment. On Windows, to wait for an event with a timer, use [URL="http://www.google.com/search?btnI=1&q=msdn+WaitForSingleObject"][b]WaitForSingleObject[/b]()[/URL] with the console input handle specified as the signal object. You'll need to use [URL="http://www.google.com/search?btnI=1&q=msdn+GetStdHandle"][b]GetStdHandle[/b]()[/URL]. [code=C++] bool countdown( int& seconds ) … | |
Re: Wait, is this a console (text) program or a Windows (GUI) program? In either case, you will have to add "event listeners": code that checks for input from the keyboard and the mouse. If a button is pressed, add the appropriate digit into the current number or invoke the appropriate … | |
Re: Er, yeah. It's one of those naming things. A virtual partition is so called because it doesn't necessarily correspond to physical structures. It's not hidden though. [EDIT] but I think it can be... [/EDIT] | |
Re: ^D terminates input. Hence, you cannot read it from the terminal directly (unless you modify the terminal's input state -- which I don't recommend). If you are sure you are reading from the terminal, you can simply say: [code=C++] string text; cout << "Please enter a bunch of lines. Press … | |
Re: I know this is old, but anyway... I've always preferred a simple variation of [B]bar()[/B]: [code=C] unsigned char rev( unsigned char b ) { unsigned char result = 0; while (b) { result <<= 1; result |= b % 2; b >>= 1; } return result } [/code] This method … | |
Re: Answers like: [quote]Which is equivalent to [inlinecode]n = n + 1;[/inlinecode] [list=1] [*][inlinecode]++n;[/inlinecode] [*][inlinecode]n++;[/inlinecode] [/list] [/quote]are meaningless. They are the same. A better answer is: [quote]What is the difference between: [list] [*][inlinecode]x = n++;[/inlinecode] [*][inlinecode]x = ++n;[/inlinecode] [/list] [/quote] Once that is understood then you can get into stuff like … | |
Re: To delete files in other directories, you must provide path information. An [b]absolute[/b] path doesn't care where your executable is: [quote]C:\WINDOWS\Media\chimes.wav /usr/bin/env[/quote](Don't delete either of those, btw.) A [B]relative[/B] path is relative to the current working directory (which may or may not be where your executable is -- it is … | |
Re: Wait... are you writing a [i]GUI[/i] application or a [i]console[/i] application? To me, MFC Dialog == GUI --> put a "[B]next[/B]" button on your form, and don't mess with [B]GetKeyboardState[/B](). | |
Hi all. I've nearly finished the home page for my wife. Sadly, I've discovered (again, surprise, surprise) IE doesn't play fair. I wanted the home page to be a simple "splash with links" kind of thing, and I used a variation of Meyer's CSS popup technique to do it. (See … | |
![]() | Re: Essentially, yes. Except a pointer goes one step further than a magic number: it is the index of an actual memory location. |
Hi all. I am designing a website for my wife's business, and I am coding it by hand -- pure HTML 4.01 Strict and CSS-1. When I loaded it into IE 6 (6.0.2900.5512.xpsp_sp3_gdr.090804-1435) I got a message complaining that it had "Active Content". (I am aware it is a result … | |
Re: The answer actually depends on which version of Windows you are using. Also, since this is a batch file, you want to suppress questions like "Do you really want to delete X?", which will really confuse and frighten your end-user. Here's a batch that [I]should[/I] work on all versions of … | |
Re: Unfortunately, there really isn't a very amazing way to do directory browsing natively. That aside, there is also useful information like this: [URL="http://delphi.about.com/od/windowsshellapi/l/aa122803a.htm"][b]Centering the Select Directory dialog[/b][/URL] at [b]about.com[/b]. Enjoy! | |
Re: That depends. What I/O interface are you using? Is it a console process? Are you using a GUI? What OS? What widget set? | |
Re: What OS are you using? If it is x86 google "dos interrupt 21h". If you are on a MIPS processor you'll need to google "mips syscall". Hope this helps. | |
First off, C++ does not know anything about the I/O device you are using. It can be a keyboard and monitor, or a file, or a network connection, or anything which can do I/O. What that means is that there is no standard way to do this in C++. That … | |
First off, C does not know anything about the I/O device you are using. It can be a keyboard and monitor, or a file, or a network connection, or anything which can do I/O. What that means is that there is no standard way to do this in C. That … | |
Re: Nice. The only problem is that you can have overflow, which would destroy the values of the variables. Use bitwise operations instead: [code=C++] a ^= b; b ^= a; a ^= b; [/code] Enjoy. | |
Re: The [URL="http://linux.die.net/man/2/wait"][b]wait[/b]()[/URL] function monitors the state of a [i]process[/i], not its I/O streams. What you really want is the [URL="http://linux.die.net/man/2/poll"][b]poll[/b]()[/URL] or [URL="http://linux.die.net/man/2/select"][b]select[/b]()[/URL] function. It also seems that you want [b][i]unbuffered[/i][/b] input on your end of the pipe. See [URL="http://linux.die.net/man/3/termios"]termios(3)[/URL] for more. See also [URL="http://linux.die.net/man/3/poll"]poll(3)[/URL] and [URL="http://linux.die.net/man/3/select"]select(3)[/URL] for good reading on … | |
Re: It is because you have misunderstood something. A [b]string[/b] is not a simple POD type -- it is an [b]object[/b] type -- which you cannot write directly to file (according to Delphi standards [and also ISO standards, but that's beside the point ;) ]). The [b]write[/b][[b]ln[/b]] functions know how to … | |
Re: A [b]std[/b]::[b]vector[/b] is guaranteed to maintan contiguous data space -- meaning it cannot handle [i]really large[/i] data. Use a [b]std[/b]::[b]deque[/b] instead. I looks much the same, but the data need not be stored contiguously -- meaning it can handle a great deal larger amount of data (because it can work … |
The End.