|
|
|
|
|
|
|
|
|
|
jonnin wrote: |
---|
since this is pretty small, try change all the [] notation to .at until you find it, fix it and then restore the (faster) [] notation. |
vector<vector<struct Pixel>>
does not require the struct; one can write: vector<vector<Pixel>>
stoi()
in multiple places?
|
|
vector<vector<struct Pixel>> does not require the struct; one can write: vector<vector<Pixel>> Why the stoi() in multiple places? You seem to have whitespace-delimited integers in input and should be able to use: int value {}; while ( ss >> value ) { v.emplace_back( value, value, value ); } const int cols = stoi(width); if ( 0 < cols ) { const int rows = v.size() / cols; if ( rows * cols == v.size() ) { pixels.resize(rows); for ( int row=0; row < rows; ++row ) { pixels[row].assign( v.begin()+row*cols, v.begin()+(row+1)*cols ); } } else { // v is not rows * cols } } else { // width is not valid } |
pixels.resize(rows);
LtL wrote: |
---|
Every time you found some unexpected errors or sth., give your ENTIRE piece of code and mark at least 1 error you found at, so that we can help you within minimal time. |
LtL wrote: |
---|
it's common for coders to find their code having errors like yours, so try to use C++ arrays instead of vectors. |
LtL wrote: |
---|
They're faster and simpler, and as long as their size is larger or equal to how much you've stored, no need to worry about overflow. |