If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Capturing files in a directory

Originally Posted by drwbns

why is it that I'm only calling dir.push_back once, yet I have 2 elements?

What we see in code statically and what the actual flow of the code happens to be are two different things. You have 2 elements because you have 2 elements. That is what you did, and that is what was done. I don't know what else to tell you. Maybe you should debug your code to figure this out. All I see is that "dir" just pops out of nowhere into your code, without any indication where it was declared, where it came from, what accessed it previously, etc.

Sure I see only one call to push_back, but how do I know if it is done once, twice, or twenty times when the program is run? You don't have a full program posted, so no one knows, how, when, or where these functions are called, or with what data they are being called with.

Also,

Code:

_tcscpy(SomeArray, dir[1].c_str());

How do you know there is an element at dir[1]? Accessing non-existent elements in an array or vector using [] leads to undefined behaviour.

Re: Capturing files in a directory

This goes back to your other discussion thread 'TCHAR correct usage'. Why are you using StringVector as a function argument when you are only returning a single name? As per the other thread, why not use string& dir as a function parameter?

Re: Capturing files in a directory

Re: Capturing files in a directory

A word to the wise. Do you know what your program is trying to do before you start to code it? is this documented? Have you designed it before starting to code? Have you defined AND DOCUMENTED what functions are required and their interfaces? Programming is a lot more than just coding. In your code might I suggest that you insert comments before each function describing what it is supposed to do, what it returns and the purpose of each of its parameters, whether they are [in] only, [out] only or both [in/out], any assumptions made about the value(s) of the [in] parameters, the state of the [out] parameters if an error occurs etc etc etc. Time spent on documentation is time well spent. Others trying to understand your code have an idea of what it should be doing and when you come back to your code in a week/month/year's time and you're forgotten what you did and why then the comments will help - also helps when trying to use a function. The interfaces to a function should be the simplest that is needed to full fill its purpose which should be only one thing.

Re: Capturing files in a directory

You might find it helpful to read 'Problem Solving, Abstraction & Design Using c++' by Friedman and Koffman. Especially sections 1.5, 1.6 and chapter 6 regarding program design. If you can't find a copy in a library, Amazon UK have the 2000 version used for £1.96 (Plus p&p).

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.