Hi, i'm new to C++ (well actually i just haven't looked at it in awhile) and I've been trying to figure out how to make my array's content depend on a condition. It's not extremely important, but I think there's got to be an easier way than what I'm using. I would like to know the best way to fully assign an array with one of many possible sets of data, depending on a condition/s. I've realized (atleast i think, correct me if i'm wrong) that the only way to store lots of values to an array without storing the elements individually or copying a different array to it (but that would be element by element too, just with a simple loop) is when you first initialize it, and nowhere else. Problem is, if i use conditions and declare/initialize the array to different possible things it has a compile error, saying that the array is undeclared when i first access it. If i dont have an unconditional declaration of the array somewhere, it won't even compile. But, the array can only be initialized when it is declared (i think, again help me out here) so i can't have more than one potential initialization. I can't declare an array and pass the address to a function (which function depending on a condition) because the array would have to already be declared to pass it, which means my oppurtunity to initialize it is gone. I can daclare/initialize different arrays unconditionally and then use conditions to copy the appropriate array to the true array, or use a two-dimensional matrix array thingy and only access a certain column (or row or whatever) in that array through the program, which column depending on said condition. There's GOT to be a simple way to do this that I'm not aware of, but HOW?! I would think there is cause It's such a simple thing, to be able to assign many values at once to an array. I know this is a long description for such a simple thing, but I also know it can be annoying when people aren't specific.
LieAfterLie 10 Light Poster
WolfPack 491 Posting Virtuoso Team Colleague
LieAfterLie 10 Light Poster
WolfPack 491 Posting Virtuoso Team Colleague
LieAfterLie 10 Light Poster
GloriousEremite 25 Junior Poster in Training
WolfPack commented: Nice. - Wolfpack +3
WolfPack 491 Posting Virtuoso Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.