谁是C++高手,有几个编程请教

来源:百度知道 编辑:UC知道 时间:2024/06/14 17:45:00
1.将计算机产生的N个随机数分为奇数和偶数两组,并将他们分别压入栈中,然后输出.
#include "stdafx.h"
#include"iostream"
#include "time.h"
#include "stack"
#include "iomanip"
using namespace std;
系统显示无定义啊,大侠.你用VC++版本是什么啊

//#include <stdafx> 这个不要了,因为这是在MFC中用的。
#include <iostream>
#include <time.h> //
#include <stack>
#include <iomanip>
using namespace std;

............(加上源程序代码)

这样就可以编译了。

#include "stdafx.h"
#include"iostream"
#include "time.h"
#include "stack"
#include "iomanip"
using namespace std;

/*随机生成的数字最大值*/
const int MAXNUM = 1000;

int main()
{
srand((unsigned)time(NULL));
/* 随机数的个数 */
int n=10;
/* 奇数栈 */
stack<int> odd;
/* 偶数栈 */
stack<int> even;
int temp;
for(int i=0;i<n;i++){
temp=rand()%MAXNUM;
if(temp%2==0){
even.push(temp);
}
else{
odd.push(temp);
}
}
cout<<"随机生成的奇数系列:\n";
while(odd.size()>0){
cout<<