小编Jor*_*res的帖子

如何在c ++中正确地将向量写入二进制文件?

感谢Mats Petersson关于如何将矢量复制到数组的解释,这看起来很有用.这是代码snipet:

#include <iostream>
#include <string.h>
#include <vector>
#include <fstream>

using namespace std;

class Student
  {
    private:
    char m_name[30];
    int m_score;

    public:
    Student()
      {

      }
    Student(const Student& copy)
      {
           m_score = copy.m_score;   //wonder why i can use this statment as
           strncpy(m_name, copy.m_name, 30); //declare it private
      }
      Student(const char name[], const int &score)
      :m_score(score)
      {
           strncpy(m_name, name, 30);
      }
      void print() const
      {
           cout.setf(ios::left);
           cout.width(20);
           cout << m_name << " " << m_score << endl;
      }
      };


      int main()
      { …
Run Code Online (Sandbox Code Playgroud)

c++ fstream

17
推荐指数
2
解决办法
4万
查看次数

调用 Rnd() 生成相同的数字

当我设置这段代码时,每次调试软件时,它都会生成相同的数字。谁能告诉我为什么会这样?

dim value as integer
value = (CInt(Int(100 * Rnd())))
messagebox.show(value)
Run Code Online (Sandbox Code Playgroud)

因为它应该是随机的。这是一个例子:(从上到下)

  • 我调试软件
  • 代码运行,并生成数字 70
  • 我停止调试
  • 我再次调试它,它再次生成数字 70

这种情况一遍又一遍地发生,前两次我认为这只是运气,但是当我这样做了几次时,它总是回到 70(例如)。

但是当我保持软件运行并一遍又一遍地运行代码时,通过使用一个按钮,它会生成完全不同的随机数。再次启动它,再次出现数字70。

vb.net random

7
推荐指数
2
解决办法
6790
查看次数

标签 统计

c++ ×1

fstream ×1

random ×1

vb.net ×1