1 2 3 4 5 6 7 8 9 10 11
|
for (int t=0;t<channel.size();t++)
{
if ( getChannel(t)==1)
{
fifo_vec[t][i]=1;
}
else
{
fifo_vec[t][i]=0;
}
}
|
This code would work based on the assumption that the size of the vector
fifo_vec
is at least
channel.size();
and that each of the vectors
fifo_vec[t]
where 0 <= t < channel.size(), have at least size
i
. If
fifo_vec
is empty, then this would cause a crash.
There is probably a better way to do this, but once you know the size of
channel
, you should call
fifo_vec.resize( channel.size() );
. If you're calling loadFifo_vec in a loop with increasing
i
, you could call
fifo_vec[t].push_back( 1 /* or 0 */);
. This places the 1 or 0 as the last element of
fifo_vec[t]
and automatically increases its size.
If you want
fifo_vec
to have
x
int vectors, each of length
y
, all initialized to zero, then call this code:
fifo_vec.resize( x, vector<int>(y, 0) );
You can then index this vector as you do in your current code.