关于随机数

jp1984 2004-03-27 11:08:48
刚开始用VC。NET 在VC。NET中用rand()函数的时候不是包含 #include<stdlib>????为什么说打不开这个头文件啊??出现这样的变态的东东
“c:\Documents and Settings\James\My Documents\Visual Studio Projects\helloworld\helloworld.cpp(6): fatal error C1083: 无法打开包含文件:“stdlib”: No such file or directory”
请VC高手解答。
...全文
68 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
angelo23 2004-03-30
  • 打赏
  • 举报
回复
……我是说vc,不是说你-_-
我基本不用vc,也没遇过“在查找预编译头指令时遇到意外的文件结尾”这个怪异的错误……
jp1984 2004-03-29
  • 打赏
  • 举报
回复
对了,楼上说的不包含 #include"stdafx.h" 是不行的。 。我调试过了 。我用的是。NET
请看结果
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"rock and roll"<<endl;
return 0;
}
“damn2.exe”: 已加载“C:\Documents and Settings\James\My Documents\Visual Studio Projects\damn2\Debug\damn2.exe”,已加载符号。
“damn2.exe”: 已加载“C:\WINDOWS\system32\ntdll.dll”,未加载任何符号。
“damn2.exe”: 已加载“C:\WINDOWS\system32\kernel32.dll”,未加载任何符号。
程序“[3136] damn2.exe: 本机”已退出,返回值为 0 (0x0)。

//#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"rock and roll"<<endl;
return 0;
}

c:\Documents and Settings\James\My Documents\Visual Studio Projects\damn2\damn2.cpp(13): fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾


就出现这样的。。怎么班
jp1984 2004-03-29
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include<iostream>
using namespace std;
long fac(int);
int _tmain(int argc, _TCHAR* argv[])
{
long n=10;
//cin>>n;
cout<<fac(10)<<endl;
return 0;
}

long fac(int n)
{
// while(n>0)
if(n==1)

return 1;
else

return fac(n-1)*n;

}
damn fatal error LNK1201: 写入程序数据库“c:\Documents and Settings\James\My Documents\Visual Studio Projects\damn\Debug\damn.pdb”时出错;请检查是否是磁盘空间不足、路径无效或权限不够

真的想死了。 。 VC怎么搞的啊??再帮我解决一下。。一定给分。
jp1984 2004-03-29
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include<iostream>
using namespace std;
long fac(int);
int _tmain(int argc, _TCHAR* argv[])
{
long n=10;
//cin>>n;
cout<<fac(10)<<endl;
return 0;
}

long fac(int n)
{
// while(n>0)
if(n==1)

return 1;
else

return fac(n-1)*n;

}
damn fatal error LNK1201: 写入程序数据库“c:\Documents and Settings\James\My Documents\Visual Studio Projects\damn\Debug\damn.pdb”时出错;请检查是否是磁盘空间不足、路径无效或权限不够

真的想死了。 。 VC怎么搞的啊??再帮我解决一下。。一定给分。
jp1984 2004-03-29
  • 打赏
  • 举报
回复
不至于吧 请问怎么写。 。
对了 。AGNELO23 你不是说我烦吧??我好象没有选SIMPLE APPLICATION啊, 不就是选新建然后选WIN32中的控制台吗???什么叫往里面加东西呢??谢谢了。 。
zzj0616 2004-03-29
  • 打赏
  • 举报
回复
vc.net下的随机数函数要自己写
angelo23 2004-03-29
  • 打赏
  • 举报
回复
受不了了……你建一个empty project试试吧,用simple application它就要往里面加东西,烦死了
古布 2004-03-29
  • 打赏
  • 举报
回复
用不用#include"stdafx.h"由你自己设定
rorot 2004-03-28
  • 打赏
  • 举报
回复
#include <cstdlib>
using namespace std;

或者
#include <stdlib.h>
angelo23 2004-03-28
  • 打赏
  • 举报
回复
“不是包含#include<time>??不要给我说又是#include<ctime>”
呃……这个……如果你不要我给你说又是#include <ctime>,那我说什么呢?恩,那我说#include <time.h>也可以……#◎%※◎#※¥×◎¥×
jp1984 2004-03-28
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include<time>
using namespace std;
//craps
int rollDice(void);
int main()
{
enum status{CONTINUE,WON,LOST};
int sum,myPoint;
status gameStatus;
srand(time(NULL));//不是包含#include<time>??不要给我说又是#include<ctime>。
sum=rollDice();
switch(sum)
{
case 7;
case 11;
gameStatus=WON;
break;
case 2;
case 3;
case 12;
gameStatus=LOST;
break;
default:
gameStatus=CONTINUE;
myPoint=sum;
cout<<"point is "<<myPoint<<endl;
break;
}
while(gameStatus==CONTINUE){
sum=rollDice();
if(sum==myPoint)
gameStatus=WON;
else
if(sum==7)
gameStatus=LOST;
}
if(gameStatus==WON)
cout<<"Player wons"<<endl;
else
cout<<"Player loses"<<endl;
return 0;
}
int rollDice(void)
{
int die1,die2,workSum;
die1=1+rand()%6;
die2=1+rand()%6;
workSum=die1+die2;
cout<<"Player rolled"<<die1<<"+"<<die2<<"="<<workSum<<endl;
return workSum;
}
zhangfjj 2004-03-28
  • 打赏
  • 举报
回复
一点都没问题

#include<iostream>
using namespace std;
int main()
{
cout<<"how can i do with vc"<<endl;
return 0;
}

Compiling...
ch2_1.cpp
Linking...

ch2_2.exe - 0 error(s), 0 warning(s)
jp1984 2004-03-28
  • 打赏
  • 举报
回复
知道了 要加 #include"stdafx.h" //这是什么东东啊???这么变态??是哪几个单词的缩写???
jp1984 2004-03-28
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
int main()
{
cout<<"how can i do with vc"<<endl;
return 0;
}
c:\Documents and Settings\James\My Documents\Visual Studio Projects\helloworld\helloworld.cpp(11): fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾

VC真的很搞笑啊。 。这又怎了???
撒分……
adamsun 2004-03-28
  • 打赏
  • 举报
回复
这是各家编译器实现的自我选择,特别是微软,他才不管什么ISO等,只要对他有利就好。

呵呵,当然谁不想这样呢?只不过微软强啊。
BrightseaChen 2004-03-28
  • 打赏
  • 举报
回复
#include <stdlib.h>
#include <time.h>
jp1984 2004-03-28
  • 打赏
  • 举报
回复
为什么是 <ctime>呢?vc为什么要用这种标准?? 因为time是从c语言中继承下来的??
angelo23 2004-03-27
  • 打赏
  • 举报
回复
#include <cstdlib>
using namespace std;
或者
#include <stdlib.h>

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧