ページ 11

処理の進み具合を表示する

Posted: 2009年11月17日(火) 14:37
by dic
たとえば下のようなプログラムで、処理の進み具合を表示したいのですが
カウンタは使用せず、イテレータを使っているので、現在の処理がどのくらいまで
進んだかを知る方法が思いつかないのですが、どういった方法があるでしょうか?
#include	<windows.h>
#include	<stdio.h>
#pragma	warning ( disable: 4786 )
#include	<string>
#include	<vector>
using namespace std;

void	Print( vector<string> *v )
{
	vector<string>::iterator p = v->begin();

	while( p != v->end() )
	{
		//	ここに全体の処理の進み具合を表示したい
		printf( p->c_str() );
		Sleep( 5000 );
		p++;
	}
}

void	Init( vector<string> *v )
{
	char	mes[80] = "ヤンマーニ\n";
	int		i;
	for( i=0; i<10; i++ )
	{
		v->push_back( mes );
	}
}

int	main()
{
	vector<string>	v;

	Init( &v );
	Print( &v );

	return 0;
}
[pre]

Re:処理の進み具合を表示する

Posted: 2009年11月17日(火) 14:41
by dic
pre タイプミスしました
#include	<windows.h>
#include	<stdio.h>
#pragma	warning ( disable: 4786 )
#include	<string>
#include	<vector>
using namespace std;

void	Print( vector<string> *v )
{
	vector<string>::iterator p = v->begin();

	while( p != v->end() )
	{
		//	ここに全体の処理の進み具合を表示したい
		printf( p->c_str() );
		Sleep( 5000 );
		p++;
	}
}

void	Init( vector<string> *v )
{
	char	mes[80] = "ヤンマーニ\n";
	int		i;
	for( i=0; i<10; i++ )
	{
		v->push_back( mes );
	}
}

int	main()
{
	vector<string>	v;

	Init( &v );
	Print( &v );

	return 0;
}

Re:処理の進み具合を表示する

Posted: 2009年11月17日(火) 15:10
by dic
下のようにして解決しました
void	Print( vector<string> *v )
{
	vector<string>::iterator p = v->begin();

	int	i = 0;
	while( p != v->end() )
	{
		//	ここに全体の処理の進み具合を表示したい
		printf( "%d:", i );
		printf( p->c_str() );
		Sleep( 5000 );
		p++;
		i++;
	}
}