感谢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) 当我设置这段代码时,每次调试软件时,它都会生成相同的数字。谁能告诉我为什么会这样?
dim value as integer
value = (CInt(Int(100 * Rnd())))
messagebox.show(value)
Run Code Online (Sandbox Code Playgroud)
因为它应该是随机的。这是一个例子:(从上到下)
这种情况一遍又一遍地发生,前两次我认为这只是运气,但是当我这样做了几次时,它总是回到 70(例如)。
但是当我保持软件运行并一遍又一遍地运行代码时,通过使用一个按钮,它会生成完全不同的随机数。再次启动它,再次出现数字70。