计算我测试程序的次数 [英] Counting the number of times I've tested a program

查看:84
本文介绍了计算我测试程序的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算我测试程序的次数?


我的第一次尝试就是:


#include< iostream>


使用命名空间std;


int main()

{

static int times_tested = 0;


times_tested ++;


cout<< times_tested;


system(PAUSE); //是的,我知道专家们不喜欢暂停

但是责备我的//老师


}


显然,它不起作用 - 静态times_tested在循环外保留其值

但是,当然,它不记得

程序已完全完成。


似乎我需要一种非常静态的指定,而不是

只保留后的价值循环,但即使在程序有
运行之后。


有没有办法做到这一点?


谢谢,


Paul Epstein

How do I count the number of times I tested a program?

My first attempt was this:

#include <iostream>

using namespace std;

int main()
{
static int times_tested = 0;

times_tested ++;

cout << times_tested;

system("PAUSE"); // Yeah, I know the experts don''t like "PAUSE"
but blame my // teacher

}

Obviously, it doesn''t work -- the static times_tested retains its value
outside the loop but, of course, it doesn''t remember the value after
the program has finished completely.

It seems that I need a sort of extremely-static designation which not
only retains the value after the loop but even after the program has
run.

Is there a way of doing this?

Thank you,

Paul Epstein

推荐答案

< pa ***** *****@att.net>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com
<pa**********@att.net> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com
我如何计算我测试程序的次数?

我的第一次尝试就是:

#include< iostream>

using namespace std;

int main()
{
static int times_tested = 0;

times_tested ++;
cout<< times_tested;

system(PAUSE); //是的,我知道专家不喜欢暂停
但是责备我的//老师

}

显然,它没有''' t work - 静态times_tested在循环外保留其值,但当然,它在程序完成后不记得值

它似乎我需要一种非常静态的指定,它不会仅仅在循环之后保留值,但即使在程序运行之后也是如此。

有没有办法做这个?
How do I count the number of times I tested a program?

My first attempt was this:

#include <iostream>

using namespace std;

int main()
{
static int times_tested = 0;

times_tested ++;

cout << times_tested;

system("PAUSE"); // Yeah, I know the experts don''t like "PAUSE"
but blame my // teacher

}

Obviously, it doesn''t work -- the static times_tested retains its
value outside the loop but, of course, it doesn''t remember the value
after the program has finished completely.

It seems that I need a sort of extremely-static designation which not
only retains the value after the loop but even after the program has
run.

Is there a way of doing this?




把它写到文件中? (然后阅读并下次递增。)


-

John Carson



Write it to file? (Then read it and increment it next time.)

--
John Carson


pa**********@att.net 写道:
我如何计算我测试程序的次数?


你可以先计算你发布同一条消息的次数,并且

努力减少这个数字...

我的第一次尝试是这样的:
[...]
有没有办法做到这一点?
How do I count the number of times I tested a program?
You can start by counting how many times you post the same message, and
working towards reducing that number...
My first attempt was this:
[..]
Is there a way of doing this?




程序完成执行后剩下的内容?绝对不是它占据的任何内存的

内容。除非你做一些特定的平台 -

,否则所有可用的内存都会被释放,所以下次当你运行你的程序时,它的数据和你想要的数据是一样的:

使用您在源中指定的值进行初始化。


那么,您可以使用什么?您可以使用任何特定于平台的外部

存储来跟踪这些事情。创建一个包含

数字的文件,在程序启动时读取它,递增它,并将它写入同一个文件中。
。如果您的程序是唯一一个要更改此文件的
,那么您应该没问题。


V



What remains after your program finishes executing? Definitely not the
contents of any memory it occupies. Unless you do something platform-
specific, all memory available to you is released, so next time when you
run your program its data are the same you intended them to be:
initialised with values you specified in your source.

So, what could you use? You could use any platform-specific external
storage to keep track of those things. Create a file which will contain
a number, read it when your program starts, increment it, and write it
out to the same file. Provided that your program is the only one that is
going to change this file, you should be OK.

V


嗯,是的,我可以把它写到文件中。但我不知道如何在下次增加
。当然,我可以手动更改数字,但是b
计算机应该不需要这些东西。我确定我只是误解你了。


Paul Epstein

Well, yes, I can write it to file. But I don''t know how to "increment
it next time". Of course, I can change the number by hand, but
computers are supposed to make such things unnecessary. I''m sure I
just misunderstand you.

Paul Epstein


这篇关于计算我测试程序的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆