deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, one thing that stands out immediately is C isn't so pretty that it allows commas in a large number. In fact, if you're exceptionally unlucky (which it seems you are), including them will be syntactically correct but semantically bonkers.

gusano79 commented: aaaand how did I miss that? +10
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just for my understanding, it means that the time complexity that we find using Big-Oh, Omega or Theta is not the actual execution time of the program?

Correct. The two are related, but not 1-to-1.

Also which method will be best from the above two methods

'Best' is subjective as it depends on your needs. However, if you're looking for execution performance with only those two options, I'd say the second is superior since you've already profiled it to be faster. ;) Further, by not removing constants you can more accurately judge the real performance difference of two algorithms. O(n) is extremely likely to be slower than O(n/2). The question at that point is how much slower, and deeper analysis of the work done at each iteration is needed to determine how significant that difference is.

Also the space required by second program will be more

The space difference is tiny and constant (one int variable), so I'd call it negligible unless you're working with an exceptionally limited environment.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nesting functions is not supported in C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Agreed with Moschops, but this is still a legitimate question.

When does it become necessary to allocate memory for an array?

Typically when the size of the array is unknown until runtime, or the lifetime of an array would be insufficient for your needs (such as returning a locally generated array from a function). Another reason might be that the array is large enough to risk overflowing the stack, but in that case you probably need to consider other data structures.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

English, a bit of Japanese, and fluent profanity.

<M/> commented: I am with you on profanity +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is your homework, not ours. We'll help if you have a specific question, as long as the specific question does not constitute "do it for me".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

They changed the Recycle Bin icon? That's my favorite feature, and the only reason I use Windows! That's it, I'm officially and irreversably moving to Minix. This travesty cannot be be reconciled. Who does Microsoft think they are? Geez!

stultuske commented: ^_^ +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so this is not language dependent right?

After a fashion. It's a language-dependent optimization, but it is very common. I would default to assuming that string literals are shared since that's a safer assumption in the general case.

in C also i am getting same results

Yes, C and C++ share roughly the same rules for string literals.

so optimisation will be always done for string literals..

It's not a guaranteed optimization, but I don't know of any modern C or C++ compilers that don't implement it.

they always reside in read only memory..

Yes, this is effectively required by both standards. A compiler can store string literals in read-write memory, but you're not allowed to take advantage of that in portable code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Good luck and have fun! :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How later on reset all elements back to 0.0?

There are a number of ways. One that comes to mind is:

v2d.assign(2, vector<double>(3));

This will completely replace the contents of the vectors with default initialized objects. However, that can be troublesome if you have pointers into the original objects. If that's the case, you're stuck with some variant of a value-replacement loop to retain the same addresses for elements:

for (auto& x : v2d)
{
    for (auto& y : x)
    {
        y = 0;
    }
}

How to clear vec entirely, free memory?

C++11 added a shrink_to_fit member function that is intended to correct the capacity based on the vector's size. However, it's not a hard requirement that memory is released, so we're still in a position where certain tricks are the only guaranteed way to ensure memory is released. For example:

vector<vector<double>>().swap(v2d);

This is a full clear and release, v2d will erase all of its elements. Alternatively, you can just let the object go out of scope and its destructor will release memory for you.

If you want to reset the vector to its original initialized state, that can be done as well given the provided definition of v2d:

vector<vector<double>>(2, vector<double>(3, 1.0)).swap(v2d);

Are there any performance degradation in using vector arrays verus conventionl arrays using new or malloc?

In theory, yes. A carefully written dynamic array can outperform std::vector for specialized code. In the general …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I thought of searching the web

And what did your web search tell you? Some of your questions are easily answered with a web search, so my answers may be somewhat sarcastic. Where the question is trivially found, I won't even bother.

How to properly override the ostream operator?

ostream& operator<<(ostream& out, const MyClass& obj)
{
    // Class-dependent insertion

    return out;
}

Of course, that implies a dependency on std::ostream, which means you can only call this operator<< with narrow streams. A more extensible overload would look like this:

template<typename CharT, typename Traits>
basic_ostream<CharT, Traits>& operator<<(basic_ostream<CharT, Traits>& out, const MyClass& obj)
{
    // Class-dependent insertion

    return out;
}

This is the non-member design. If the function requires access to private members, you can make it a friend.

What exactly is big O notation?

A way of calculating the growth rate of algorithms. Click Here.

How to count primitive operations?

Please elaborate.

Is there a way to see how much memory my program uses?

Yes, but it's platform-dependent.

Can I use redirected input in eclipse or Xcode?

Yes, you can redirect from the command line or within code. I'd suggest doing it from the command line as you don't need code changes and in-code redirection can be tricky.

What can I truly do with memory management in C++?

Manage memory...

Why isn't everything written in c++?

Why doesn't everyone …

rubberman commented: D, you have a lot more patience than I do! :-) +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a compiler optimization. Given that string literals are read-only, there's no reason to create two separate instances of the same string literal in memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you show us your code, we can offer advice on improving it. For now, I can only answer your questions.

Does fscanf not work with negatives?

It works fine, provided you use a signed format specifier like "%d".

Do I have to read in the entire file, then parse by fgets or fgetc (or whatever the individual char function is)?

Probably. I say this because each line represents a row of the matrix, and fscanf will not tell you when it reaches a new line. All whitespace is equal where fscanf is concerned.

Why is this such a pain in the donkey? If it were integers it seems like it would be a lot easier.

My guess is it's a pain because you're trying to match a series of lines in the file to rows in an array. I strongly doubt this would be alleviated by storing integers in the file rather than floating-point. It's really a parsing problem, not a data representation problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I humbly apologize and throw myself upon the mercy of the court...

I find you guilty and sentence you to ten lashes with a wet noodle. After that, you must endure...THE COMFY CHAIR! Muahahahaha!

ddanbe commented: You're a cruel judge, with no compassion! +15
gusano79 commented: I didn't expect th-- AAH NO, NO, NOT THE EXTREMELY SOFT CUSHIONS...! AAARGHHCHGBKL#BO%@B%$LB!!!#@$ +10
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

stdout and stdin are not tied, so the output from printf is only guaranteed to be flushed if you print a newline or call fflush. In this case, you probably don't want to print a newline, so the only solution is fflush:

int main ()
{
    int i;

    printf ("Enter integer: ");
    fflush (stdout);

    if (scanf ("%d", &i) == 1)
    {
        printf("Detected %d\n", i);
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That design sounds dicey to me. My preference would be for the main form to manage itself completely, where temporary dialog forms are opened as needed and pass back information objects through properties or events for the main form to own and manage beyond the lifetime of the dialog.

For example:

// Main form
List<InventoryItem> _items;

void addItem_Click(object sender, EventArgs e)
{
    using (var dlg = new AddItemDialog())
    {
        if (dlg.ShowDialog == DialogResult.OK)
        {
            _items.Add(dlg.Item);
            RefreshInventory();
        }
    }
}

// AddItemDialog
public InventoryItem Item { get; private set; }

void buttonOK_Click(object sender, EventArgs e)
{
    Item = new InventoryItem(...);

    // Populate the item with form element data

    DialogResult = DialogResult.OK;
}
darkagn commented: Well explained with good example +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd just escape it:

string[] items = str.Split(new char[] { '°', '\''});
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if the str were to be an array of two dimensions, eg. str[][] format how would it look like?

In a function declaration, only the first dimension size can be omitted. All subsequent dimensions must have a matching size to the array you pass, so it would be something like this:

int mult(int x, int y, int str[][10]);

If you need variable sizes for other dimensions, this is a case where you'll need to simulate an array using pointers completely:

int mult(int x, int y, int **str);

But that changes how you create and use the "array". A proper 2D array won't be compatible with that function signature.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Typically modern systems will use a cryptographically secure one-way hash to store credentials. Provided the password is strong, coupled with judicious salting, it can be quite difficult to break given only the hash result. Not impossible, mind you, but much more secure than using straight up encryption.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need a data structure that can hold anonymous (unnamed) objects of the struct. For an unknown number of records, I'd suggest a linked list. Here's something to get you started:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct record
{
    char *name;
};

struct node
{
    struct record data;
    struct node *next;
};

static struct node *list = NULL;

int main(void)
{
    struct node *temp;
    char line[BUFSIZ];

    // Build the list from user input
    while (1)
    {
        fputs("Name: ", stdout);

        if (fgets(line, sizeof line, stdin) != NULL)
        {
            // Clean up the newline character
            line[strcspn(line, "\n")] = '\0';

            if (line[0] == '\0')
            {
                // A blank name stops input
                break;
            }

            temp = malloc(sizeof *temp);

            if (temp != NULL)
            {
                // Populate the record and prepend it to the list
                temp->data.name = _strdup(line);
                temp->next = list;
                list = temp;
            }
            else
            {
                perror("Error creating record");
            }
        }
        else
        {
            // Error or EOF stops input
            break;
        }
    }

    // Display for testing purposes
    for (temp = list; temp != NULL; temp = temp->next)
    {
        printf("%s\n", temp->data.name);
    }

    // Clean up our dynamic memory
    while (list != NULL)
    {
        struct node *next = list->next;

        free(list->data.name);
        free(list);

        list = next;
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The issue is all the programs I'm making at the moment are boring, they don't serve a purpose really so it's just learning that is the problem.

I understand that only too well. When I was learning, the toy programs to test out new ideas and practice felt empty and boring. That's one of the reasons why I developed an interest in compilers and standard libraries. While I literally burned through three copies of K&R due to them falling apart from constant use, my favorite C book is still The Standard C Library and it encouraged me to write a number of my own implementations.

That obsession with tool building kept my interest when learning. More importantly, it gave me a base to become the go-to toolsmith programmer at work. :D These days I work more with C#, but reading the .NET reference source for fun and using dotPeek to decompile whatever I can get my hands on makes me think that I never lost that initial spark of wanting to look under the hood for seemingly innocuous things and figure out how they really work.

You might try finding a similar niche that keeps your drive going but also promotes your programming education.

00Gambit commented: thanks +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Dave and I go way back, from cprogramming.com circa 2000 to flashdaddy (now entropysink, IIRC), and Daniweb. The banter and sharing of knowledge was top notch every time. :D I think my fondest memories were the many MSN Messenger chats we had about programming and whatever else came to mind.

There are a handful of people from these forums that I consider friends, and Dave remains number 1 on that list.

From a programming perspective, I was always amazed at his bit twiddling skills since that's something I had to think about yet he could bang out anything without breaking a sweat.

On all forums, I honestly don't remember Dave losing patience or failing to help someone thoroughly. Given that he was very active on cprog before coming to Daniweb, and the tradition of heavy snark there, his restraint was very impressive. Compare it with Narue or Salem, who never really gave up the snarky traditions of cprog when posting on Daniweb.

I distinctly remember his passing, as well as how hard it hit me. I think I completely lost interest in Daniweb for a good two or three weeks because of it. That might surprise some people since Dave and I never met face to face, but it's a testament to how real online friendships can be.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The bad news is that if you're not digging it this early, hardcore programming probably isn't for you. Casual programming can remain fun, of course, but any push into serious development or even a career doesn't strike me as promising.

The good news is that it can be easy to get burned out, especially if you're pushing hard to learn and don't really have a solid goal. My suggestion would be to take some time off and do other things[1]. When you feel the itch and return to programming, give it a go and if you lose interest again quickly, put some thought into whether you really want to be a programmer.

That's probably not the answer you wanted, but in my experience, good programmers love it to death. You have to to keep up with constant changes, constant learning, and being slapped in the face with errors and bugs at every turn. Real coding isn't pretty, and it takes a certain type of personality to tolerate it for any measure of time.

[1] Maybe a game that's popular with techies and programmers like go.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Should I be ashamed of myself

Certainly not. I spent a number of years on cprogramming.com before moving to Daniweb. The choice was obvious: cprog had a lot of experts at the time and Daniweb did not, I could offer more by switching. Do what's best for you, my friend. If you find StackOverflow more rewarding, then rest assured your contributions to Daniweb thus far will be appreciated far into the future.

castajiz_2 commented: tnx for the support +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How about a retroactive featuring of Dave Sinkula, sort of as a memorial to a good friend and a great member? Obviously there can't be an interview, but I think it would be a nice gesture.

~s.o.s~ commented: That's a good idea +0
ddanbe commented: Yes, great! And take AD second. +0
iamthwee commented: +1 +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

To answer your immediate question, printf(" %d",ocean[ROWS][COLS]); should be printf(" %d",ocean[r][c]);. The former is flat out wrong in that officially oceanOne[10][10] does not exist. In practice it does for your compiler, but only because that's the memory location for oceanTwo[0][0]. That's why the first call gives you random numbers while the second call gives you zeroes. However, if you populate the two arrays with other values, the real problem will be more apparent: both calls to printOcean display the wrong thing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also watch out @deceptikon, there is already a ForEach method on List<T>

Yup, and only List<>, which is why the extension method is beneficial. ;)

I don't know what the interaction would be here.

In method overload resolution, more specific ownership takes precedence. So any locally defined method throughout the inheritance hierarchy will be preferred over an extension method. In this case, when both List<> and the IEnumerable<> extension method are in scope, List<>.ForEach will always be selected for a List<> object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm, I'm not sure I see the benefit in this case. Though variations on ForEach are relatively common. As an example, I have an extension method for ForEach over an IEnumerable<> and another that reports progress over iteration:

/// <summary>
/// Performs an action on each item in an enumerable collection.
/// </summary>
/// <typeparam name="T">The type of items in the collection.</typeparam>
/// <param name="action">The action to perform.</param>
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
{
    foreach (var item in items)
    {
        action(item);
    }
}

/// <summary>
/// Performs an action on each item in an enumerable collection with a progress indicator.
/// </summary>
/// <typeparam name="T">The type of items in the collection.</typeparam>
/// <param name="action">The action to perform.</param>
/// <param name="startPercent">Starting progress percentage.</param>
/// <param name="finishPercent">Progress percentage after all items have been traversed.</param>
/// <remarks>
/// The progress percentage is passed to the action for use by the caller.
/// </remarks>
public static void ForEach<T>(this IEnumerable<T> items, Action<T, double> action, double startPercent = 0, double finishPercent = 100)
{
    double progress = startPercent;
    double progressRange = finishPercent - startPercent;
    double progressDelta = progressRange / items.Count();

    foreach (var item in items)
    {
        action(item, progress);
        progress += progressDelta;
    }
}

Replacing a for loop though? I can see it to a certain extent if you want to encourage a more functional style of coding, but use of for should be relatively rare these days anyway. Further, Linq already has Enumerable.Range which somewhat intersects with your extension method's purpose.

ddanbe commented: Thanks for sharing. +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As soon as i put 7 on im lagging all over the place!!!

XP also had significantly smaller hardware requirements for responsiveness. Example, you could get away with 512MB of RAM on an XP box easily, but on a 7 box it won't be usable.

Tcll commented: I got XP running on 256MB (now 384MB) :) +4
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It pains me to recommend WiX, given that the learning curve is so high. However, if you want a free option that's not gimped, I think it's the best one.

pritaeas commented: Nice. +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

wasnt this site meant for learning

It is. But some effort is expected on your end. Asking easily searchable or vague questions and expecting no snark in return is unreasonable. We're not a replacement for brain function and research.

It was meant as a test.

Yes, and the test was obvious. Many of us have seen such "tests" countless times before, and they have rarely been in good faith. Hence, the responses you've gotten.

Im not trying to make this site into a morals teaching one , It should remain as it is but i want that every ones question be recieved warmly and answered instead of dejecting them and proclaiming how stupid they are

Translation: I'm not trying to change how you do things, I'm just trying to change change how you do things.

I think you'll find that good questions receive good answers while bad questions (ie. lazy, vague, easily answered with STFW or RTFM, having a poor attitude, etc...) are responded to in kind.

As an example, you've started 6 threads. One was an introduction, one was borderline lazy, and the rest were exceptionally lazy. It's no mystery why you haven't been received well.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sadly no one could answer this simple question

If you already know the answer such that you know it's simple, why not enlighten us and put the Daniweb geniuses to shame?

Ahmad Imran commented: C++ is an improved version of C created by Bjarne Stroustrup in the 80s, it was originally just C with classes and object orientence +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

According to the documentation, it's the index in the source array at which copying begins. Presumably the underlying question is why is that overload being used when the source index is 0?

The reason is that values from the source are being appeneded to the destination rather than copying to the destination starting at index 0, which is default behavior for the simpler overloads. Of the four overloads you have, only two of them offer the option to begin copying to the destination at a different index than 0, and both of them require a starting index for the source.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And also, out of curiousity, are we allowed to put .gifs up as our avatars?

Provided the GIF is within our size restrictions, you can upload it fine, but if the original is animated the uploaded avatar will not be animated. The reason for this is we do some image processing prior to storage of avatars, and only the first frame of a multi-frame image gets used.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Structure it however you want. It takes time and experimentation to find a project structure that works for you though. As an example, I tend to use something like this:

/codebase
/documentation
/libraries
/media
/output
/tools

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Compiler vendors are allowed to add onto the standard C libraries. We sometimes refer to those additions as an extension.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

getline isn't a standard function, so your book is correct. The problem is your compiler supports that function as an extension, so the easiest approach would be to change the name of the function in your code to something else.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Posting actual code might help instead of paraphrasing lines onesie twosie.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You could count the number of zeroes inside a number N with the following algorithm

And if the number begins with zeroes? What if the number exceeds the range of your numeric type? The best approach to handle input as it's typed is to work with it as a string rather than a numeric data type, like in Stefano's hint.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm sure I've mentioned this type of wrapper class for accessing databases in a provider-agnostic manner before, but never posted a functional implementation. So here it is. Questions, comments, and suggestions are welcome as always. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, the most widely supported method would be the ctime library:

#include <ctime>
#include <iostream>
#include <utility>
#include <string>

using namespace std;

pair<string, int> weekday(int month, int day, int year)
{
    tm date = {0};

    // Set the date properties
    date.tm_mday = day;
    date.tm_mon = month - 1;
    date.tm_year = year - 1900;

    // Let the library correct any discrepancies in the parameters
    time_t normalized_date = mktime(&date);
    char buf[1024];

    // Extract the user-friendly weekday name
    strftime(buf, sizeof buf, "%A", localtime(&normalized_date));

    return make_pair(string(buf), date.tm_wday);
}

int main() 
{
    pair<string, int> day = weekday(1, 1, 2014);

    cout << day.first << "(" << day.second << ")" << '\n';
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem seems to be in your ToString override in that you want a format that's difficult to attain using enumerations. It can be done, of course. I'd probably approach it something like this:

namespace CS_TexasHoldem
{
    public enum CardSuit : int
    {
        CLUBS = 'c',
        DIAMONDS = 'd',
        HEARTS = 'h',
        SPADES = 's'
    }

    public enum CardValue : int
    {
        TWO = 2,
        THREE,
        FOUR,
        FIVE,
        SIX,
        SEVEN,
        EIGHT,
        NINE,
        TEN,
        JACK = 'J',
        QUEEN = 'Q',
        KING = 'K',
        ACE = 'A'
    }

    class Card
    {
        private static Dictionary<CardSuit, string> _cardSuits;
        private static Dictionary<CardValue, string> _cardValues;

        static Card()
        {
            _cardSuits = new Dictionary<CardSuit, string>();
            _cardValues = new Dictionary<CardValue, string>();

            foreach (var suit in (CardSuit[])Enum.GetValues(typeof(CardSuit)))
            {
                _cardSuits.Add(suit, ((char)suit).ToString());
            }

            foreach (var value in (CardValue[])Enum.GetValues(typeof(CardValue)))
            {
                if ((int)value <= 10)
                {
                    _cardValues.Add(value, ((int)value).ToString());
                }
                else
                {
                    _cardValues.Add(value, ((char)value).ToString());
                }
            }
        }

        public CardSuit Suit { get; private set; }
        public CardValue Value { get; private set; }

        public Card(CardSuit suit, CardValue value)
        {
            Suit = suit;
            Value = value;
        }

        public override String ToString()
        {
            return _cardSuits[Suit] + _cardValues[Value];
        }
    }
}

Note that the public interface only supports the enumerations. This saves you trouble checking against invalid values. The class then manages conversion of those enums into a friendly string format.

However, a better approach would be to avoid that string conversion entirely and let the calling application decide how it wants to handle display of cards. Right now you're doing something low level that's probably …

ddanbe commented: Nice! +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

my first question is whether a deck of cards should have a base class of card

It doesn't make sense to me, personally. A deck of cards is not a card, it's a collection of cards, so composition is the better choice over inheritance:

public class Deck
{
    public List<Card> Cards { get; set; }

    ...
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's valid syntax, but guaranteed to be confusing and very likely to become incorrect as more members are added to the class. The private qualifier only explicitly applies to suit, and the public qualifier will only apply to your constructor. value will have default visibility, which in this case is private.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Click the Chat button on the bottom bar. This will open the chat window and reset your pending chats count. It will also turn off the inline chat popup until you receive another chat in your chat box.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how can I use it ??

A "dynamic array" is really nothing more than simulating an array. Once created, you use it very much like a regular array.

how can I allocate and intialize it ???

This will allocate a dynamic array of 10 pointers to int, then initialize the pointers with an increasing value. The values are printed by iterating over the array and dereferencing each pointer. Finally, the dynamic array is freed:

// Allocate
int **a = new int*[10];

// Initialize
for (int i = 0; i < 10; i++)
{
    a[i] = new int(i);
}

// Use like an array
for (int i = 0; i < 10; i++)
{
    cout << *a[i] << '\n';
}

// Release
delete[] a;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It depends quite a bit on the contents of your file. Let's say that the file looks like this:

resistor
inductor
capacitor
diode
transistor
circuit

Then you would replace your push_back calls with something like this:

ifstream in("words.txt");

if (in)
{
    string line;

    while (getline(in, line))
    {
        words.push_back(line);
    }
}

It would be easier to show you where you're going wrong if your code actually had an attempt to read the file. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is it valid to use an integer variable as a condition?

Yes. This:

if (var)

Is logically synonymous with this:

if (var != 0)

Provided var has an implicit conversion to an integer or boolean type, it's perfectly valid and makes for nice shorthand in some cases. In this case, 0 is false and any non-zero value is true.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Off the top of my head, I might approach it two ways:

  1. Simply have the application check periodically for new records. This would be the easiest to implement, but it may see derading performance over time.

  2. Use a notification service that pushes new records to client applications so that they can pop up a notification box or something. This would be my preference, probably using a WCF service.