跳到正文

科技·工程

STAR_CPP 使用教程(一):IO 与 Random 类

BoHyCar约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年1月15日
收录
2026年1月15日
更新
2026年2月8日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

如果你不知道 STAR_CPP 是什么,请看这里: STAR_CPP 介绍

一、IO 类

定义:STAR::IO io;

函数或运算符功能例
IO(string,string)绑定输入输出文件(若没有则自动创建)。 io("data.in","data.out");
<<向输入文件里写入数据。io<<3<<" "<<5;
createof(string)根据输入文件和标程绝对路径,向输出文件里写入数据。io.createof("D:/main.exe");

二、Random类

定义:STAR::Random rand;

函数功能例
random(double,double)在给定范围内生成随机浮点数。rand.random(1,1000);
randint(int,int)在给定范围内生成随机整数。rand.randint(1,1000);
randstr(int,[string])根据字典和长度生成随机字符串,否则以所有大小写字母和数字作为字典。rand.randstr(10,"0123456789");
randperm(int)生成随机排列。rand.randperm(10);
choice(vector)从容器中随机选择一个元素。vector<int> a;rand.choice(a);
原文