免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1764 | 回复: 5
打印 上一主题 下一主题

[C++] c++使用中的一些问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-04-24 22:15 |只看该作者 |倒序浏览
1、vc++6.0里不能用random()函数吗?
2、为什么不能用<iostream>;而非要用<iostream.h>;?
3、vc++6.0里单步运行怎么运行?
  
我是初学者,这些问题可能菜了点,但还是请大家帮忙!
还有,我的是win2000pro系统,不是linux系统。
听说vc++6.0是老版本了,不知道是否有新版本可以下载?
还有,那里有连机帮助系统msdn下载(中文的)?

论坛徽章:
0
2 [报告]
发表于 2003-04-25 12:46 |只看该作者

c++使用中的一些问题

标准c中是rand而不是random并且要include stdlib.h

使用iostream也可以

但是要using namespace std;
可以看置顶的faq及c++基本教程

3的话要有断点才可以step
这在所有调试器上都是一样的
包括gdb

论坛徽章:
0
3 [报告]
发表于 2003-04-25 19:23 |只看该作者

c++使用中的一些问题

在此我给出MSDN中关于rand()的解释吧,具体你可以查看MSDN。
至于下载MSDN和VC,你直接到北大天网(http://e.pku.edu.cn)搜索关键字“MSDN”和“visual studio”,然后点击“搜索文件”,即可找到FTP下载地址。

**************************************************
srand
Sets a random starting point.

void srand( unsigned int seed );

Routine Required Header Compatibility
srand <stdlib.h>; ANSI, Win 95, Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

None

Parameter

seed

Seed for random-number generation

Remarks

The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.

Example

/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

#include <stdlib.h>;
#include <stdio.h>;
#include <time.h>;

void main( void )
{
   int i;

   /* Seed the random-number generator with current time so that
    * the numbers will be different every time we run.
    */
   srand( (unsigned)time( NULL ) );

   /* Display 10 numbers. */
   for( i = 0;   i < 10;i++ )
      printf( "  %6d\n", rand() );
}


Output

    6929
    8026
   21987
   30734
   20587
    6699
   22034
   25051
    7988
   10104

**************************************************
rand
Generates a pseudorandom number.

int rand( void );

Routine Required Header Compatibility
rand <stdlib.h>; ANSI, Win 95, Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

rand returns a pseudorandom number, as described above. There is no error return.

Remarks

The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand.

Example

/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

#include <stdlib.h>;
#include <stdio.h>;
#include <time.h>;

void main( void )
{
   int i;

   /* Seed the random-number generator with current time so that
    * the numbers will be different every time we run.
    */
   srand( (unsigned)time( NULL ) );

   /* Display 10 numbers. */
   for( i = 0;   i < 10;i++ )
      printf( "  %6d\n", rand() );
}


Output

    6929
    8026
   21987
   30734
   20587
    6699
   22034
   25051
    7988
   10104


Floating-Point Support Routines

See Also   srand

论坛徽章:
0
4 [报告]
发表于 2003-04-25 19:54 |只看该作者

c++使用中的一些问题

楼上很热心
支持一下

论坛徽章:
0
5 [报告]
发表于 2003-04-28 22:05 |只看该作者

c++使用中的一些问题

谢谢大家!

论坛徽章:
0
6 [报告]
发表于 2003-04-28 22:22 |只看该作者

c++使用中的一些问题

#include <iostream>;是基于STL(标准摸版库)的。
而#include <iostream.h>;是老式的输入输出流头文件。

VC.60不支持#include <iostream>;(据说后来出了补丁,我也不太清楚),
需要Visual C++ .NET

关于VS.NET安装需要Winxp, Win2000.而Win98只能安装远程调试和组件。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP