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

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
dic

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

#1

投稿記事 by dic » 15年前

たとえば下のようなプログラムで、処理の進み具合を表示したいのですが
カウンタは使用せず、イテレータを使っているので、現在の処理がどのくらいまで
進んだかを知る方法が思いつかないのですが、どういった方法があるでしょうか?
#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]

dic

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

#2

投稿記事 by dic » 15年前

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;
}

dic

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

#3

投稿記事 by dic » 15年前

下のようにして解決しました
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++;
	}
}

閉鎖

“C言語何でも質問掲示板” へ戻る