早上好,
我打算做以下几件事:
#include <new>
//Boost for sparse and cstdint
#include <boost/numeric/ublas/vector_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/cstdint.hpp>
int main(){
boost::numeric::ublas::compressed_vector<boost::int_fast8_t> *p = new boost::numeric::ublas::compressed_vector<boost::int_fast8_t>[100];
boost::numeric::ublas::compressed_vector<boost::int_fast8_t> t (12,2);
p[0] = t;
for(boost::int_fast8_t i=0;i<t.size();i++)
{
p[0](i) = i;
}
std::cout << p[0] << std::endl;
}产量: 12(
然而,如果我使用标准类型,即int,它将按预期打印范围。
我做错了什么吗?还是这是不可能的?
我很欣赏uint8_t在32位机器上的速度并不快,但我需要节省内存。
蒂娅!
发布于 2014-03-21 16:40:52
您的int_fast8_t实际上等效于char (签名或无符号)类型,并且在打印时被视为如此。
auto& data = p[0];
std::copy(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;修正(通过将值解释为整数,而不是字符)。
与数组、稀疏性、stdints等无关。只需碘流:)
看吧,住在Coliru
https://stackoverflow.com/questions/22563368
复制相似问题