mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Nice tool ... rolleyes ... to figure out if you can run Windows 7, you need to run this tool, and to run this tool, you need one of the following operating systems:

Windows 7, Windows Vista, Windows XP Service Pack 2
.NET Framework 2.0 or higher if running Windows XP

Needless to say, if you are running any of these systems on your PC, it's a pretty good guess that Windows 7 will run exactly the same as the system you are currently using. Duhh..

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@RevJim, yep, that's pretty much how it looked like in my street the next day, all cars frozen in place up to their axles. The only picture I can find is from right after the pipes burst at 3am (in that picture, my apartment was the one right in the middle, with the spiraled stairs, next to the graffiti'd wall).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The problem is that English has complex spelling and complex phonetics (subtle diphtongues and all that), and, to make matters worse, the two don't correlate with each other.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As triumphost says, the C++ does come with both a sleep_for and a sleep_until function. Of course, these functions cannot come with any kind of standard guarantees about timing or being a busy-wait or not, or anything like that, but it provide the comforting thought that someone better than you spent some time implementing the most optimal sleep function for whatever platform you are using, and that is generally good enough for me.

While C++ could have extended or replaced the C functions with a more complete DateTime class or classes, to date they haven't done so

Yes they have, a few years ago. It's in the chrono header. It doesn't exactly go as far as doing "date", it only does "time". For dates, you would have to either rely on the legacy C time library or rely on boost gregorian.

Schol-R-LEA commented: Ah, I wasn't familar with <chrono>. I'll have to read up on that. Thank you. +10
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Whenever people start talking about recursion I feel compeled to dispell a few myths and make a few "real world" points. Just a few things I'd like to clarify or point out:

Which [iteration/recursion] is to be used depends on the nature of the problem at hand,

The nature of the problem at hand does not influence to choice of iteration vs. recursion. Although it is true that some problems are more easily expressed as recursions, in fact, probably most non-trivial algorithms are more naturally expressed as recursions, but that has no bearing on the implementation choice; implementation and analysis are two very different things. I sometimes will write out the recursive form in the comments to express what the algorithm does, and then, implement it in the iterative form.

What determines the choice of iteration versus recursion is if there are some guarantees: limited recursion depth, no degenerate / pathological cases that could cause extreme recursion depth, function call overhead is insignificant compared to the rest of the code, or the code is not destined for production code or released software (e.g., some small side-project or toy example). It's actually quite rare that all these assumptions apply, but if they do, then recursion can be better when you can avoid relying on freestore memory allocations (dynamically allocating the stack or queue required for the algorithm's state).

and to a great degree, the language being used. Some languages, especially Lisp and the various functional languages, strongly favor …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The contents of the array are indeterminate, which is the "official" reason for the undefined behavior.

There is obviously a gray zone between indeterminate values and undefined behavior. If it wasn't for trap representations (which I doubt still exist on any hardware at all), there would really be no reason why reading a variable of indeterminate value would cause undefined behavior. It might be the case that, very strictly-speaking, this is UB, but certainly not in practice.

And from what I have read on trap representations (which I just learned about in this thread), it seems that (1) in C++, trap representations only apply to floating-point numbers, and that (2) any IEEE-compliant processor must not have trap representations on floating-point numbers. And also, even C99 integer trap representations seem so rare that even the committee members looked for example architectures and could not find any. I think that the standards (C/C++) could be re-worded to say that it is well-defined behavior to read an indeterminate value (such as an uninitialized variable), and it would not change anything at all for any implementation or architectures that anyone still uses (it seems the last processor to have a trap representation on floating point numbers was an old DSP chip from the 80s).

Is there any other reason why reading a indeterminate value would be undefined behavior?

I don't mind indeterminate values at all if I access an array with no initial value. I just don't want my program …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I got prit confused with ddanbe

WOT!?

It wouldn't be the first time a Flamish guy is mistaken for a Dutch. ;)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Why is accessing data in an uninitialised array undefined behaviour?

It's not really clear whether this is undefined behavior or not. If you read uninitialized data, you will read a garbage value, i.e., whatever arbitrary combination of bits that happens to be in that memory location at the time of the allocation. That's what's going to happen in pretty much 99.9999..% of platforms (unless you compile in debug mode where "uninitialized" data is often initialized for easily spotting such errors).

Undefined behavior is a technical term pertaining to the C++ standard. What the standard says here is that if you dynamically allocate an array, the elements get "default-initialized", which is the standard term to mean "if class type, then default constructor is called; if trivial type (e.g., int), then left uninitialized". Then the standard mentions that uninitialized primitive values have "indeterminate value", which (to me, at least) implies that reading that value is well-defined behavior, it's just the value that is indeterminate. In that case, it's well-defined behavior, it's just that the behavior is to obtain a "garbage" value.

Anyhow, these are just SO-style language-lawyers' discussions.

Any ideas what I could do to keep the speed of uninitialising without breaking any rules?

The rule is that you cannot meaningfully (UB or not) read the value of an uninitialized variable (part of an array or not). But, obviously, you can write to it. You could pre-allocate an array before you come to the point of having values …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
Introduction

The subject of this tutorial is a bit more advanced than the subjects I have tackled in the past, but I hope this will find some interested readers. From time to time in C++, programmers find themselves torn apart between using a Generic Programming style which primarily involves the use of templates and compile-time mechanisms (e.g., STL), and using a Object-Oriented Programming style that often favors inheritance and run-time dispatching mechanisms (e.g., Qt). As it is so often the case, there is no obvious "winner", i.e., there is no paradigm that should always be preferred, even within a single problem domain.

This tutorial will take you through a number of alternative techniques and will describe how these choices affect the performance and flexibility of the code. The novice-to-advanced programmers will discover in this tutorial a number of somewhat classic techniques that will certainly come in handy. The expert programmers might rediscover those techniques but mostly will see in this tutorial an occasion to reflect on some of the trade-offs that they face and the surgical ways to manipulate them.

Working Example: Printing the Fibonacci Sequence

For this tutorial, we'll be using a very simple example problem: printing a Fibonacci sequence. As is usual in these kinds of examples, the techniques that I will show will be much too complex for the simple example used (i.e., overkill), but the point is to imagine a more complicated scenario where the techniques shown are more appropriate given the complexity of the problem. …

LaxLoafer commented: Impressive. +4
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Happy New Year! (in advance or belated, depending on where you are!)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

And yes, text editor preferences tend to generate major wars! :-)

A computer geek is not really a computer geek without the occasional text-editor flame-wars! ;)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You cannot use sublime in the terminal. I think this discussion is about terminal-based text editors, such as nano, pico, vi, and emacs.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

1.What is the "Global Rebuilding" technique exactly?

I would assume that it refers to a complete destruction of the tree and a complete reconstruction of it. This is what I usually call a "collect-and-rebuild" process. When you have a tree or a sub-tree that needs to be re-balanced, some traditional approaches (e.g., in red-black trees or AVL-trees) involve doing some tinkering with the structure, such as tree rotations to re-shape the tree by swapping or splitting some parent-child relationships. However, in some cases, this is too hard or not practical at all (e.g., in contiguous storage, like a cache-oblivious implementation). So, instead of trying to repair an unbalanced tree or subtree, it is easier to just collect all the node values that you want to keep (e.g., removing those you want to delete, or adding those you want to insert), destroy the tree, and re-build it back from the array of node values that you collected. In many kinds of search trees, this is the only option when you need to re-balance a tree or subtree.

It may sound like a horrible solution, because it seems really expensive to continuously destroy and rebuild the tree whenever you add or remove elements from it, but in reality, this is amortized by the fact that it is very rare that a tree becomes unbalanced enough to requires a complete reconstruction. Typically, the majority of insertions and deletions don't cause any significant imbalance in the affected subtree. But when it does, …

rubberman commented: Good explanation Mike. +12
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I would not consider assembly to be a waste of time either. You will find that this "low-level" knowledge that you gained there will be useful later. If anything, it informs the way you program or "see through" the code.

I couldn't afford anything that has a price, and I don't think that pirating is good nor older versions of VS

Well, there is the Express version, which is free and essentially as good as the full version. The full version (non-free) is only really useful for professional development companies and large teams. None of the full-version features are really useful for lone coders or amateurs.

But then again, VS is not an IDE that I would recommend in general.

As for C++, it needs too much code and focus on not the main things for me. I want to create productively.

In general, C++ allows you to work on many different levels. If you find yourself "needing too much code" or "not focusing on the right things", then it only means that you are working on the wrong level. There are many high-level libraries in C++ that allow you to do a lot with very little code. What you are describing is called RAD (Rapid Application Development), and there are several ways to do RAD in C++. I would suggest that you try to use Qt with QtCreator as an IDE (both are free). There are also other options like C++Builder

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Mike - did you get any part of the ice storm that hit hogtown?

No, we're quite alright over here. I think some people in Montreal were affected, and then some in the townships (south of Montreal). But I'm in Quebec City for the holydays and we only got 1 foot of snow during that storm, no ice rain or hail.

I recall one morning when I was a teenager I got up early to milk cows (central Iowa), and the themometer read -40C.

I recall in 2011 when, at 3am at night, the main water pipe in my street froze over under the -45C temperature (-50F). The freezing of the water in the pipe caused the whole pipe to burst open in the street, pooring freezing water over all the cars and street. I would have been really bad if it wasn't for the 1.5 meter snow banks lining the sidewalks, which contained the flow of water, which quickly (about 1 hour) froze over on the street, covering the entire street with about 1 foot of solid ice, with parked cars completely stuck in it for the unlucky who didn't rush out to move their car in time. It took a couple of weeks to recover (clean up, repair pipes, unfreeze pipes, etc.).

But it's not that bad, we only get maybe a couple of days per winter below -40C, and maybe a couple of weeks total below -30C. Below -20C is usual. And between …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I have done this several times with different computers in labs and stuff. It is purely a matter of configuring the routers to assign reserved IP addresses to your computer and then configure your subnet masks to make sure that packets going to the internet are routed through your internet connection and packets going to the local network are sent to the other router. Most routers can be configured to have a list of "reserved" IP addresses that it will give out to particular computers when they do a DHCP request. This is the most reliable way to give a computer a "fixed" IP address. The other option is to disable DHCP on your router and configure a fixed (manual) IP address on your computer, but that can lead to some issues, so, the first option is preferrable.

When you select your IP addresses, make sure they are different enough. Typically, routers give out addresses in the range 192.168.0.x (which corresponds to the default subnet mask of 255.255.255.0). You can usually configure them to use another range of addresses, like 192.168.1.x or some other number in the second-last position (you should keep the first two numbers as they are, those are the reserved numbers for local networks). If you can, you should configure your two routers to use different second-last numbers in their addresses. If you can do that, then you can keep the default 255.255.255.0 subnet mask. A few times, with some old routers, I was unable to change …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

A bitmask is a special number that has a bunch of bits (0/1) set to 1 such that when you do a bitwise AND with another number, you get only those bit values. This is useful in many contexts, it basically extracts only the parts of a number that are of interest for a particular task.

One example where a bitmask is used is for subnet masks on IPv4 addresses. An IPv4 address is a 32bit integer value that represents the address of a device on the internet (computer, router, server, etc..). It is usually written in the form 192.168.0.1 where each number is one byte (8 bits) which is a number between 0 and 255. So, the four numbers together make up the 4 bytes (32bits) address. A typical "local network" subnet mask is 255.255.255.0 which is a number which has all leading 24bits set to 1. If you do a bitwise AND between the mask (255.255.255.0) and the address 192.168.0.1, you get 192.168.0.0. And if you do it with the address 192.168.0.23, you also get 192.168.0.0. You see how this can be useful to determine if the address is part of the particular local network or not.

Another example of where bitmasks are useful is when you use different bits of a single number to mean different things, which are usually called "flags". It's a basic mechanism to store a bunch of simple options within a single number (if you have enough bits to accommodate it). Here is …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It never seizes to amaze how cold Winnipeg can get in winter.

Here it's -27C

I guess that cold front will make its way over here (Quebec) in a couple of days, just in time for a new year in the freezing cold.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Really funny. Any time I see people arguing about language X vs. Y, I'll link to that article. But, if you see me arguing about language X vs. Y, then, obviously, I'm right! ;)

<M/> commented: XD +10
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As Ancient Dragon says, this is an English-speaking forum. I do understand French and could read the assignment you posted, which talks about a simple "tokenization" problem. For the benefit of others, the assignment asks to create a C++ program that (1) reads text from a file and then displays it to the screen, and (2) ask the user for a list of delimiter characters and then prints (to screen and to another file) the list of segmented "words" (or tokens) from the original text.

Now, about helping you solve this, we have the policy not to just provide finished solutions to people's homework problems. You need to show efforts towards solving the problem yourself and you must ask questions about specific problems that you are stuck with.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It should be fine. I'm not sure about any particular compatibility issues, but I don't think that a move from 512Mb to 2Gb of RAM on an 8 year old desktop should be a problem. It's a very common "upgrade", or way to give an old computer a second life.

Talking about giving the computer a second life, I would suggest opting for a Linux distribution instead of WinXP. For one, WinXP is being phased out, and you really don't want to have any WinXP computer when even Microsoft doesn't provide security updates, let alone any support whatsoever. Any version of Windows that are more recent is probably not going to run at all on that old computer. With a Linux distro installed, you'll get a modern OS that will run very smoothly on that machine (and there are light-weight distributions of Linux for older hardware), and it's low-maintenance, perfect for secondary usages like backups or home servers.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

If you cannot get as far as to boot from another media, then it means that the bios boot sequence has been altered. Microsoft has a long history of making tweaks to the bios firmware as part of an intermediate step in the installation (or update, I guess). Basically, if something did not go right during the installation, your computer is stuck in a state where all the bios tries to do is continue the installation, ignoring any other booting rules (such as booting from a rescue media (USB / CD / DVD)).

What you will need to do is jump the cmos jumper to do a factory reset of your bios. Here are some basic instructions, but you will want to find instructions specific to your computer hardware (specifically, the motherboard). Doing this will certainly make it possible to boot into a rescue media and install / re-install whatever you want. I've had that exact same problem before (it was back in the days of Win2000, but it seems old habits die hard at Microsoft).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Merry Christmas to y'all! Wish you all the best and good health. (and don't get too fat on holyday food!)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Thanks for that detailed explanation! I hadn't read it like that, but I understand his twisted logic now. Under the insane assumption that a nationalized healthcare system somehow kills off all sick people at incredible speed and somehow induces mass-amnesia for all friends and family of the departed, then, yeah, what he says makes perfect sense.

Oh.. what a fool I was to assume that the reason Tatcher couldn't touch the NHS was that everyone clearly knew that it works orders of magnitude better than a privatized system. Same reason no one would dare to touch this system in Canada either. How foolish of me to think that! :rolleyes:

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

To me, Santorum's words are very clear. He is saying that providing 'free' healthcare to all is a ploy by the Democrats to save the lifes of a bunch of people (poor and middle-class) who would normally die under the current system, and that those people who will benefit greatly from this system will be forever grateful and inclined to keep voting for the Democrats and never allow a repeal of the 'free' healthcare system. In other words, "we're done", as he says, referring to the Republican party and the TEA party's anti-healthcare agenda. Then, he describes the "clever system" that has worked for the GOP for so long, which is to let people die so quickly and ruthlessly that they can never really have the energy or the means to fight for a better healthcare system, and at the same time, reducing the population that is likely to vote for a party that seems (on the surface) to advocate for better healthcare. (but, of course, both parties receive about as much donations and bribes from the big healthcare players (pharma, insurers, providers, etc.), making this whole thing a rather pointless political circus anyway)

These really are insane words, but what else would you expect from Santorum.

As for that speech by Alan Grayson, that was basically him (Dem.) attacking the Republicans by stating (with a punchline) the de-facto GOP position on this issue, which is the same thing that Santorum described as the GOP strategy in his speech. That's …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Same as Jim. All I can seem to recall is that I might have gained a rank in one place and lost a rank in another, that's about all I can see.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

-11C, 15-30cm of snow, 80km/h winds. And some hail. Roads are not closed, but not recommended.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I can't see how that could go wrong, given the pissy tendencies of many SO regulars. :rolleyes:

Yeah. Their fuses are about as short as their answers. Their ability to accept criticism is inversely proportional to their reputation points. Their concern about helping others can only reside in the very narrow space between questions that are: too redundant with others; too specific; too long to answer; too subjective; and, not answerable with a copy-pasted answer riddled with links to other SO threads. A convenient philosophy for any lazy educator (how often do teachers do the same? And how much do you like those teachers... :rolleyes: ).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yes, but if you develop in Visual Studio, you are assuming that they have a number of Visual C++ redistributables already installed. The CRT is often dynamically linked too (unless you change the option). And then there could be many other stuff, some of which may not be there in a "standard windows install". Normally, you would have to package your application in an installer that would check all those things and install distributable versions of them. That's the "burden" of creating distributable applications.

Frankly, this is a bridge you should cross when you get to the river. In general, figuring out how to distribute the application has little if any impact on the actual code, it is only a matter of compilation options and what libraries you link to. For Qt, this is rather straight-forward (they recommend just putting the few Qt DLLs in the directory of the executable). For now, I think you should just concentrate on coding up the application, and worry about deployment if and when you get to that point.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As stated on the Peppermint website, your system is on the limit of being good enough to run the OS. So, that might just be the reason behind your slow issues. You could try an older versions with less requirements.

One thing to check is, of course, the md5sum on the ISO that you downloaded.

Also, it goes without saying: you got the 32bit version, right? If you got the 64bit version, it will be extremely slow for sure.

Then, to run the system live (to "try it", before installing), you should really be using a USB drive instead of a CD/DVD. This is because when you run from a CD/DVD, the system has to be entirely loaded to RAM. But if you run from a USB, the configurations can remain on the USB drive, and there is swap space on it too, making it much faster overall. I'm sure the installation would run better off a USB too. I'm sure you have an old USB stick laying around with 1-2Gb of space on it.

Next, it loads into peppermint as if I were trying it before installing but it won't let me use the mouse or keyboard so I cant do anything more from there.

Last I remember when installing a recent version of a Ubuntu derivative, the installation process (after the basic settings are passed) looks as if it's booting into the OS, although it's still part of the installation process (there are a few more …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Wow, that's crazy. It's crazy that these people can listen back on what they said and probably can't even see how insane they sound.

This makes me think of this classic speech:
"The Republican health-care plan: 'Don't get sick! And if you do get sick... Die quickly!'"
-- Alan Grayson, Rep.(D-FL)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, as AD says, the dynamic linking option may seem like more troublesome in terms of distribution, but it is the only viable option in the broader context. You can't have the users re-install a statically-linked version of Qt for every new Qt application they install. The same principle goes for every other major library or framework.

In fact, one of the major criticism about Windows is that it does not have a proper package management system (like all Linux, BSD, Unix-like, and Mac OSes) that can manage all the libraries installed on the system, and also its culture of proprietary (not shared) software means that there is a lot of repetitive installations, a lot of "reinvent the wheel" work, and very bloated systems for the users who install many applications. This is how Windows gets incredibly bloated and slow over time. Try to reuse things using dynamically linked options, and you'll be part of the solution, as opposed to being part of the problem.

And if your users are tired of complicated installation processes and bloated systems, just tell not to use Windows. ;)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It's basically user preference. Vi is meant to be a very comprehensive editor, and it has tons of commands and special features. Nano is more of a basic text editor (think "notepad in the terminal", i.e., nothing more than copy-paste, exit-save). I generally prefer nano because for the times that I need a terminal-based text editor, I usually don't need a very complicated editor, and I don't like having to remember all the commands when all I ever need to do is write some text and then "save-and-exit" (and nano has a command-reminder at the bottom). I guess if you are used to vi (and know the commands) it is "better" than nano in the sense that it has more features, but to me, it's needlessly feature-rich for most things I do in a terminal-based text-editor.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I doubt that you will be able to find any decent GUI library/toolset that can be statically linked with your application. All the GUI libraries that I know of are dynamically linked, including Win32, MFC, WinForms, VCL, Qt, wxWidget, GTK+, and SDL. Some of these are open-source, and thus, could be re-compiled into static libraries (which, btw, will require significant tweaking of the build script). This is simply one of these cases where the demand for static library versions of the libraries is so low that it really doesn't make sense to provide and maintain it.

I would ask: Why do you absolutely want a statically-linked GUI library?
Because I cannot see any reason why you would want this.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What part of his stereotype do you think is false?

He sort of has this "dorky accountant" look, which is what most people think IT people or programmers look like. But I have never met any of these mythical "dorky accountant" programmers. I think programming and IT is a very creative endeavour, and that creative personality is usually reflected, one way or another, in people's looks. Finding an average and "conformist" picture for some representative daniweb mascot is a pointless endeavour.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@AD: I don't think that the OP is really interested in a Qt vs. .NET debate in this thread. It would be like answering a question about a problem with some C++ code, and recommend as an answer to opt for a completely different language instead. It's off-topic. In any case, any .NET code is definitely never completely compiled to "native" code, this is by design of the whole .NET framework. When writing programs or libraries for the .NET framework (through C# or C++/CLI, or whatever), the "compiler" will compile that code to CIL, which is a high-level pseudo-assembly code that acts as an intermediate language. A .NET "executable" is actually just a launcher that launches the .NET framework (if not already running) and launches the execution of the CIL code embedded in that "executable". When CIL code is "executed", it is, in fact, interpreted on the fly (also called Just-In-Time compilation). There is a world of difference between CIL and actual native code (like you would find in an object file (.o/.obj) from some C/C++ compilation, you could say "conceptually similar" but certainly not similar in practice). And yes, to answer the OP's concerns, .NET programs will be bloated and slow, non-portable and heavy-weight (heavy distributables), due to the reliance on the .NET framework and JIT compilation.

before I do something irreversible to my IED environment (vs 2010)

Installing the Qt add-on for Visual Studio is neither irreversible nor is it gonna interfere with anything else, in …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

There are a number of ways to do it. Here are some options:

1) Use the C++ counterpart to "SortedList" which is called std::set (see docs). This is a container of elements that are sorted. However, just like SortedList, this is implemented using a binary search tree (some kind of red-black tree) that uses "links" between nodes. For storing elements of 16 bytes each (probably a POD-type), and when you only have a few thousand of them, this solution will be very far from optimal in terms of performance. Probably about as good as the C# version, which is terrible by C++ standards.

2) Keep a sorted array (vector) and insert elements into it. Something like this:

void addElementToVector(std::vector<T>& v, T elem, std::size_t max_size) {
  if( ( max_size <= v.size() ) && ( elem >= v.back() ) )
    return; // nothing to do.

  if( max_size > v.size() ) { // if empty room in v
    // add room at the end:
    v.push_back(elem);
  };
  // find the position for the element
  auto pos = std::upper_bound(v.begin(), v.end()-1, elem);
  // and move the array around it:
  std::move_backward(pos, v.end()-1, pos+1);
  // and set the new element:
  *pos = elem;
};

You can look at the docs for upper_bound and move_backward to figure out how this works. It's a simple matter of finding the proper place to put the new element within the existing array, and then move the sub-array by one position such that the new …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Are you finding yourself using the new homepage now?

Yes. And I'm glad Fred is gone!

<M/> commented: ikr +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Why is it at 5? Arg, this is so confusing.

Because you are reading two names per iteration when you do this:

while(names >> students)
{
    names >> lastInFile;
    i++;
}

You read one name into students and then another into lastInFile. Because you have 8 names, and you first read one before the loop, you then get 7 names to read in the loop, which takes 4 iterations. This is why you get 5 printed out (1 + 4). You need to read only one name per iteration:

while(names >> lastInFile)
{
    i++;
}

and that should give you the correct result (8) for the counter, and lastInFile should contain the last valid name from the file.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

yo mama is so fat that when she went for a studio photo shoot, they had to use a panoramic lens.

<M/> commented: lol +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Here are some "safer" alternatives:

1) use the namespace only within a function body:

#include <iostream>

int main()
{
    using namespace std;
    cout << "Blah, blah, blah";
    return 0;
}

This limits the scope of the namespace usage, reducing the scope at which names could clash.

2) use the individual items instead of the whole namespace:

#include <iostream>

using std::cout; // at global scope

int main()
{
    using std::endl; // or at function scope

    cout << "Blah, blah, blah" << endl;

    return 0;
}

Again, this limits the name-clashes while reducing the verbosity when you only need a few elements of the namespace.

3) create a namespace alias:

#include <boost/program_options.hpp>

namespace po = boost::program_options;

int main(int argc, char** argv) {
  // use elements of the program_options namespace
  //  with po:: instead of boost::program_options::

  // ...

  return 0;
};

I had to show this with Boost.Program-Options, just as an example of a case when there can be a fairly long namespace name. Creating such an alias is a simple trick to reduce the verbosity.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

My name means C programer....

lol. I always thought it meant your name was C.P. Roger, e.g., Cletus Prometheus Roger.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yo mama is so stupid that when she went to donate plasma, she brought her television set.

cproger commented: lol +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@<M/> I guess you never heard of the notion of feet in prosody, nor about rhymes. Rev Jim's version is a beauty in both of these aspects. I'm just saying you shouldn't change your career path to become a song-writer just yet.

<M/> commented: ha... +0
cproger commented: :) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It's my impression that viruses are not nearly as much of a problem as they used to be. Maybe it's because anti-virus software have "won" the fight. I think it also has to do with the history of it all. In the early days of PCs (win95 - winXP), a lot of kids were discovering what could be done and had fun creating viruses that screwed with people's computers. Then, the viruses started to focus on gathering info and powering ads (i.e., spyware / adware). And now, that is no longer need since most people's info and habits reside in the servers they connect to regularly, and those spyware / adware stuff is built into nearly all services people use everyday, so why bother writing viruses for that. But hey, I might be wrong, since I migrated to Linux a few years back, viruses are just some vague memories from a past life.

I think a similar situation might be happening with computer hardware. I remember that in the early days of PCs, hardware failures were much more common than today. My first computer (200MHz) required a replacement of the CD drive, the motherboard, the hard-drive, and one RAM stick, not to mention having to re-format and re-install the OS roughly every 4-6 months. My second computer (733MHz) was only a little bit better. But after that, I never had to re-install an OS, nor replace faulty hardware components (except recently changed by power supply). It's my general impression that …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Just read the docs. It's simply:

DecimalFormat myFormatter = new DecimalFormat("#,##0.0#");
<M/> commented: Thanks :D +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I guess you have to add this line at the top:

import java.text.DecimalFormat;
<M/> commented: ... i now feel dumb. :D +9
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You should notice this line:

Line 3 Right: The total is 10123607318 

That is one big number. In fact, it is larger than what you can represent with a 32bit integer type, which is what int is in Java (the number is about 10 billion, and the max for an int is about 2 billion). This is an integer overflow problem. You need to sum-up the total into a larger integer than that, like long.

The second problem is about formatting only:

Line 4 Wrong: Average is -124975.0
Line 4 Right: Average is -124,975.00 

You have your output set to putting a comma between thousands. You need to change that setting. I think you can just do:

 DecimalFormat myFormatter = new DecimalFormat("#.0#");
System.out.println("Average is " + myFormatter.format(total * 1.0D / count));
<M/> commented: Thank you! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

-15C and about 1 foot of snowfall today.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

what he is really doing and how can i protect my account ? and what methods he's using ?

You should ask him. But I have a feeling he is imaginary... and that you're just fishing for some tips on how to hack people's accounts.

ddanbe commented: Absolutely! +14