'rand' 的问题,6.0里面是不是没有这个函数
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::endl;
using std::rand;
using std::srand;
using std::time;
int main() {
const int limit1 = 500; //Upper limit for on set of random values
const int limit2 = 31; //Upper limit for another set of values
cout << "First we will use the default sequence from rand(). \n ";
cout << "Three random integer from 0 to " << RAND_MAX << ": "
<< rand() << " " << rand() << " " <<rand() << endl;
cout << endl << "Now we will use a new seed for rand().\n ";
srand((unsigned int)time(0)); //Set a new seed
cout << "Three random integer from 0 to " << RAND_MAX <<": "
<< rand() << " " <<rand()<<" " << rand()<<endl;
return 0;
}这样子的时候运行不成功,
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(7) : error C2039: 'rand' : is not a member of 'std'
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(7) : error C2873: 'rand' : symbol cannot be used in a using-declaration
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(8) : error C2039: 'srand' : is not a member of 'std'
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(8) : error C2873: 'srand' : symbol cannot be used in a using-declaration
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(9) : error C2039: 'time' : is not a member of 'std'
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(9) : error C2873: 'time' : symbol cannot be used in a using-declaration
执行 cl.exe 时出错.
去掉下面这个就可以了
using std::rand;
using std::srand;
using std::time;
把这个内容去掉就可以运行,而且达到取随机数的效果
为什么用了using后就不可以了呢`?
#include <cstdlib>
#include <ctime>
using std::cout;
using std::endl;
using std::rand;
using std::srand;
using std::time;
int main() {
const int limit1 = 500; //Upper limit for on set of random values
const int limit2 = 31; //Upper limit for another set of values
cout << "First we will use the default sequence from rand(). \n ";
cout << "Three random integer from 0 to " << RAND_MAX << ": "
<< rand() << " " << rand() << " " <<rand() << endl;
cout << endl << "Now we will use a new seed for rand().\n ";
srand((unsigned int)time(0)); //Set a new seed
cout << "Three random integer from 0 to " << RAND_MAX <<": "
<< rand() << " " <<rand()<<" " << rand()<<endl;
return 0;
}这样子的时候运行不成功,
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(7) : error C2039: 'rand' : is not a member of 'std'
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(7) : error C2873: 'rand' : symbol cannot be used in a using-declaration
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(8) : error C2039: 'srand' : is not a member of 'std'
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(8) : error C2873: 'srand' : symbol cannot be used in a using-declaration
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(9) : error C2039: 'time' : is not a member of 'std'
E:\PROGRAM FILES\LEMOLIANXI\C++入门\Random\random integers.cpp(9) : error C2873: 'time' : symbol cannot be used in a using-declaration
执行 cl.exe 时出错.
去掉下面这个就可以了
using std::rand;
using std::srand;
using std::time;
把这个内容去掉就可以运行,而且达到取随机数的效果
为什么用了using后就不可以了呢`?
...全文
相关推荐
Excel中随机生成四位或六位数字验证码的方法!.pdf
基于“互联网+”课程思政的高职经济法教学改革研究.pdf
Qt里产生随机数.doc
qt教程
matlab代码实现BP网络对函数的拟合
此代码为matlab代码,实现BP神经网络对函数的拟合,此代码未使用matlab工具箱函数,而是将整个前馈和反向传播过程用代码形式编写出来,因此具有很重要的参考价值
PSO求解多目标优化问题代码,pso优化算法,matlab源码.zip
PSO求解多目标优化问题代码,pso优化算法,matlab源码
粒子群 matlab简单优化过的 TSP
简单的matlab版本的粒子群算法 可解决TSP问题 简单优化改进版本 fitness 和最后函数自己写 只给了主体函数 其余只有几行代码了 自力更生才学的会啊


