I have std::vector<unsigned char> m_vData;
std::vector<unsigned char> m_vData;
m_vData.max_size()always returns -1. why does this happen?
m_vData.max_size()
Perhaps because before you browse, you assign it to a signed type. The return value of max_size is usually size_tone that is an unsigned type. Direct conversion to say int on many platforms will return -1.
size_t
Try instead
std::vector<unsigned char>::size_type v1 = myVector.max_size();
Note that it max_size()returns vector::size_typeunsigned, so you see a negative number due to converting it somewhere (you really get a very large unsigned number back).
max_size()
vector::size_type
, ( , ).
( ). vector::size() vector::capacity().
vector::size()
vector::capacity()
Note that on most platforms std::vector<unsigned char>::max_size, it will most likely be the same as std::numeric_limits<unsigned int>::max(), which of course is -1 when converting to a signed int.
std::vector<unsigned char>::max_size
std::numeric_limits<unsigned int>::max()
Source: https://habr.com/ru/post/1720917/More articles:PyDateTime_IMPORT macro does not initialize PyDateTimeAPI variable - c ++Web Design Template Visio Stencil - visioHow to add navigation property for complex type Entity Framework - visual-studioHow to assign page property to another page in ASP.NET - c #How to make a makefile using specific libraries in different ways? - makefileOpenCV grid area - c ++Table row not updating correctly using MVC Ajax - asp.net-mvcProblems Using ListBox and Observable Collection as Debug Log - .netWhat does a C ++ compiler do to create an object? - c ++Client Screen Resolution Detection - flexAll Articles