ehsan_faal
سه شنبه 02 تیر 1394, 01:57 صبح
سلام من از کتابخانه boost واسه تولید اعداد رندوم استفاده میکنم.
این یه بخشی از کدیه که قصد دارم کاملش کنم که یه وکتور دو بعدی رو مقداردهی میکنه(یعنی باید میکرد ولی نمیدونم مشکلش چیه).
ممنون میشم اشکال کارم رو بگید:
template <class T>
void InitializeRandomMatrix(vector<vector<T>> & C, int MinRange, int MaxRange)
{
int satr = C.size(), sotun = 0;
if (satr)
{
sotun = C[0].end() - C[0].begin();
}
else
return ;
boost::mt19937 gen(time(0));
boost::normal_distribution<T> nd(MinRange, MaxRange);
for (int r = 0; r < satr; r++)
{
for (int c = 0; c < sotun; C++)
C[r][c] = nd(gen);
}
}
و اینم main :
void main()
{
const int row = 3;
const int column = 3;
srand(time(0));
vector<vector<double>> Mat(row, vector<double>(column,0));
InitializeRandomMatrix(Mat, -13, 57);
DispArray(Mat);
cout << Maximum(Mat)<< endl;
cout << Minimum(Mat) << endl;
system("pause");
}
و اینم ارورش:
1>------ Build started: Project: Vector, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\ehsan\desktop\C++\vector\vector\source .cpp(92): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2715): error C4996: 'std::_Fill_n': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2701) : see declaration of 'std::_Fill_n'
1> c:\boost\include\boost-1_58\boost\random\detail\polynomial.hpp(114) : see reference to function template instantiation '_OutIt std::fill_n<boost::random::detail::polynomial_ops::digit_t*,si ze_t,boost::random::detail::polynomial_ops::digit_ t>(_OutIt,_Diff,const _Ty &)' being compiled
1> with
1> [
1> _OutIt=boost::random::detail::polynomial_ops::digi t_t *
1> , _Diff=size_t
1> , _Ty=boost::random::detail::polynomial_ops::digit_t
1> ]
1>c:\users\ehsan\desktop\C++\vector\vector\source .cpp(21): warning C4244: 'argument' : conversion from 'time_t' to 'const uint32_t', possible loss of data
1> c:\users\ehsan\desktop\C++\vector\vector\source .cpp(95) : see reference to function template instantiation 'void InitializeRandomMatrix<double>(std::vector<std::vector<double,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>> &,int,int)' being compiled
1> with
1> [
1> _Ty=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
این یه بخشی از کدیه که قصد دارم کاملش کنم که یه وکتور دو بعدی رو مقداردهی میکنه(یعنی باید میکرد ولی نمیدونم مشکلش چیه).
ممنون میشم اشکال کارم رو بگید:
template <class T>
void InitializeRandomMatrix(vector<vector<T>> & C, int MinRange, int MaxRange)
{
int satr = C.size(), sotun = 0;
if (satr)
{
sotun = C[0].end() - C[0].begin();
}
else
return ;
boost::mt19937 gen(time(0));
boost::normal_distribution<T> nd(MinRange, MaxRange);
for (int r = 0; r < satr; r++)
{
for (int c = 0; c < sotun; C++)
C[r][c] = nd(gen);
}
}
و اینم main :
void main()
{
const int row = 3;
const int column = 3;
srand(time(0));
vector<vector<double>> Mat(row, vector<double>(column,0));
InitializeRandomMatrix(Mat, -13, 57);
DispArray(Mat);
cout << Maximum(Mat)<< endl;
cout << Minimum(Mat) << endl;
system("pause");
}
و اینم ارورش:
1>------ Build started: Project: Vector, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\ehsan\desktop\C++\vector\vector\source .cpp(92): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2715): error C4996: 'std::_Fill_n': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2701) : see declaration of 'std::_Fill_n'
1> c:\boost\include\boost-1_58\boost\random\detail\polynomial.hpp(114) : see reference to function template instantiation '_OutIt std::fill_n<boost::random::detail::polynomial_ops::digit_t*,si ze_t,boost::random::detail::polynomial_ops::digit_ t>(_OutIt,_Diff,const _Ty &)' being compiled
1> with
1> [
1> _OutIt=boost::random::detail::polynomial_ops::digi t_t *
1> , _Diff=size_t
1> , _Ty=boost::random::detail::polynomial_ops::digit_t
1> ]
1>c:\users\ehsan\desktop\C++\vector\vector\source .cpp(21): warning C4244: 'argument' : conversion from 'time_t' to 'const uint32_t', possible loss of data
1> c:\users\ehsan\desktop\C++\vector\vector\source .cpp(95) : see reference to function template instantiation 'void InitializeRandomMatrix<double>(std::vector<std::vector<double,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>> &,int,int)' being compiled
1> with
1> [
1> _Ty=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========