C++ 在两个输入c和x2B之间留出时间+;
我有我的一个小项目,希望得到一些帮助。 这是到目前为止的代码C++ 在两个输入c和x2B之间留出时间+;,c++,codeblocks,C++,Codeblocks,我有我的一个小项目,希望得到一些帮助。 这是到目前为止的代码 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(timetaker) { } int after() { srand(data from above); for (int x = 1; x<2;x++) { cout <
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(timetaker)
{
}
int after()
{
srand(data from above);
for (int x = 1; x<2;x++)
{
cout << 1+(rand()) << endl;
}
}
#包括
#包括
#包括
使用名称空间std;
内部主(计时器)
{
}
()后面的int
{
srand(以上数据);
对于(int x=1;x考虑到这个问题的模糊性,我想说这是你最好的资源:
如果将要调用的代码放在要从中调用代码的位置之前,会更容易。可以按照以下说明获取srand()
的时间值,并从main()
传递它
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void after(time_t seed)
{
srand(seed);
for (int x = 1; x<2;x++)
{
cout << 1+(rand()) << endl;
}
}
int main()
{
do_stuff(time(NULL));
}
#包括
#包括
#包括
使用名称空间std;
之后无效(时间\u t种子)
{
srand(种子);
对于(int x=1;x我看不出任何问题。顺便说一下,您缺少main
和之后的的返回值。您也不能执行int main(计时器)
这应该是什么
srand函数应该使用main
函数中的数据?您需要在之后在函数int中传递一些参数
我也不建议使用使用namespace std;
,因为如果您要实现自己的cout函数,这可能会导致未定义的行为。使用std::
是更好的方法。不过,这是您的选择,在这段代码中也可以
如果您想与时间共事,可以查看以下链接:
我将看到链接thxI将thx用于快速回复。我将查看回复thx以获得帮助
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void after(time_t seed)
{
srand(seed);
for (int x = 1; x<2;x++)
{
cout << 1+(rand()) << endl;
}
}
int main()
{
do_stuff(time(NULL));
}