干杯! --M 我不知道为什么他不能用矢量。 boost :: array实际上并不是标准,我不知道它是否会成为。它是否比图书馆中的矢量更便携??这是向量的重大缺点。 除非sizeof(int)在他的 系统中为1,否则他将超过他的4K内存。 br />I''ve allocated 4K memory and I''d like to use std::fill to fill each 1Kwith a different value. Note: I could easily use a vector/deque butI''m interested in a C style array.int main(){int const max = 0x1000;int *ptr_mem = new int [ max ];int initial(1);for ( int idx(0); idx < 4; ++idx ){std::fill ( ptr_mem, ptr_mem + 0x400, initial );ptr_mem += 0x400; // move to the next 1Kinitial += 1; // change the value}// call a display function to send output to a text - for assessmentdelete [] ptr_mem;ptr_mem = 0; // just in case.}I''m coming up short. I''m sure part of the problem is my limitedunderstanding of std::fill (back to the text in a minute on this). Inthe meantime, how would I achieve this? 解决方案Looks OK. What''s the problem? Looks OK. What''s the problem?Except that ptr_mem was changed from its original location. Unless itis changed back before the delete[], there will be problems! Dare I askwhy the OP can''t use a vector (or perhaps boost::array or a staticallyallocated array)?Cheers! --MI don''t know why he can''t use vector. boost::array isn''t actuallystandard and I don''t know if it''s ever going to be. Is it more portablethan vector across libraries? That''s the big downside of vector.He will be exceeding his 4K of memory unless sizeof(int) is 1 on hissystem. 这篇关于用std :: fill进行实验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 01:51