这个程序总是有内存错误,高手帮看下
#include <iostream>#include <sstream>
#include <time.h>
using namespace std;
class jockgame
{
public:
jockgame();
void newjock();
void xipai();
void printjock();
private:
string jock[52];
};
jockgame::jockgame()
{
char a[4]={3,4,5,6};
string b[13]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
int n=0;
for(int i=0;i<4;i++)
for(int j=0;j<13;j++)
{
jock[n]=a[i]+b[j];
n++;
}
}
void jockgame::printjock()
{
for(int i=0;i<52;i++)
cout<<jock[i]<<" ";
if(i%12==0)
cout<<endl;
cout<<endl<<endl<<endl;
}
void jockgame::xipai()
{
srand(time(0));
int n;
string s;
for(int i=0;i<52;i++)
{
n=rand()%52+1; //这个地方有问题,是不是随机函数调用的太多了?
s=jock[i];
jock[i]=jock[n];
jock[n]=s;
}
}
void main()
{
jockgame jock;
jockgame();
jock.printjock();
jock.xipai();
jock.printjock();
}
[ 本帖最后由 jiansilang 于 2011-3-9 12:08 编辑 ]