c++不能正确显示随机数
C++ Not displaying Random number correctly
我想为温度生成一个随机数。我使用的代码如下:
int Temp()
{
// genreate random temperture
// initialize random seed:
srand ( time (NULL) );
// generate number between 1 and 100:
int t = rand() % 100 + 1;
std::cout << t << std::endl;
return t;
}
程序运行时,不是显示1到100之间的数字,而是显示以下内容:
010C1109
有人能解释一下哪里或为什么会出错吗?
编辑:如果有人想知道我用了下面的话:
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <map>
#include <cstdlib>
#include <cstring>
#pragma once
如何选择数字的显示方式:
std::cout << std::hex << t << std::endl; //displays in hexadecimal
std::cout << std::dec << t << std::endl; //displays in decimal
在我的例子中,我看到十六进制58,十进制88(5*16+8)。以下是使文章完整的官方链接。
c++论坛:http://www.cplusplus.com/forum/windows/51591/细节解释道:http://www.cplusplus.com/reference/ios/dec/
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 整数不会重复超过随机数
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 程序崩溃并显示"std::out_of_range"错误
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 从数据库实时显示QT c++中的数据
- if数组上的随机数
- Rand() 没有显示随机数,请帮助我了解出了什么问题:)
- 测量我的随机数数组打印的时间始终显示为 0 秒
- 如何在当前时间,显示标头并将随机出生日期分配给X人数(C )时如何播种随机数生成器(C )
- 向控制台显示随机数
- 如何将随机数组值一起添加到另一个数组中,然后在计算出现的值时显示它们?C++
- c++不能正确显示随机数
- 排序前显示的随机数
- 如何创建两个独立的对象,显示随机数10次