C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[64689] ofstream 도 전역 변수로 할수 있나요?
뽀뽀중 [kissjung] 1272 읽음    2011-06-23 20:09
간단하게 dxf (캐드 도면 화일)을 만들 었습니다.
라인, 폴리라인, 원, 글자등의 요소를 함수로 만들어 dxf 코드를 출력 하게 하였습니다
그런데, 각 함수 마다, 화일을 open, close를  하게 하였는데,
출력 하는 개체들이 많아지니, 프로그램이 무한정 느려 지네요.

아마도 함수 호출 마다 화일을 open, close 해서 그런듯 한데..

ofstream 을 한번에 열고 닫게 할수가 있나요??

=========아래와 같이 코딩을 하였습니다.============
main.cpp
DxfBegin() ;
DxfCircle(1.5, 10.2, 50.2);
DxfEnd()

별도의 DxfWrite.cpp 화일 입니다.

void DxfBegin() {
	// Creation of an output stream object in text mode.
	// Header section of every dxf file.
	ofstream To_Dxf(AsDxfSaveFileName.c_str(), ios::out);

	To_Dxf << 0 << endl;
	To_Dxf << "SECTION" << endl;
	To_Dxf << 2 << endl;
	To_Dxf << "ENTITIES" << endl;

	To_Dxf.close();
}

void DxfEnd() {
	// Creation of an output stream objet in text mode.
	// end of sequence objects of dxf file.
	ofstream To_Dxf(AsDxfSaveFileName.c_str(), ios::app);

	To_Dxf << 0 << endl;
	To_Dxf << "ENDSEC" << endl;
	To_Dxf << 0 << endl;
	To_Dxf << "EOF";

	To_Dxf.close();
}

void DxfCircle(double radius, double x, double y) {
	// Propeties of a circle not bound in any AutoCAd version
	// In AutoCAD 2000 we can have more less 4000 lines of code here.

	// Creation of an output stream objet in text mode.

	ofstream To_Dxf(AsDxfSaveFileName.c_str(), ios::app);

	// Draw the circle
	To_Dxf << 0 << endl;
	To_Dxf << "CIRCLE" << endl;
	To_Dxf << 8 << endl;
	To_Dxf << 0 << endl; // Layer number (default layer in autocad)
	To_Dxf << 10 << endl; // XYZ is the Center point of circle
	To_Dxf << x << endl; // X in UCS (User Coordinate System)coordinates
	To_Dxf << 20 << endl;
	To_Dxf << y << endl; // Y in UCS (User Coordinate System)coordinates
	To_Dxf << 30 << endl;
	To_Dxf << 0.0 << endl; // Z in UCS (User Coordinate System)coordinates
	To_Dxf << 40 << endl;
	To_Dxf << radius << endl; // radius of circle

	To_Dxf.close();

}


여기서

ofstream To_Dxf(AsDxfSaveFileName.c_str(), ios::app);

To_Dxf.close();
를 main.cpp 에서 한번 열고 닫기 하고..
별도의 화일에 있는 함수에서는 화일을 열고 닫기를 하지 않는 방법이 있나요?

주변에 물어볼 사람이 전무 하므로 코드가 간단 하면, 자세히 알려 주시면 좋겠습니다.

미리 감사 드립니다.

+ -

관련 글 리스트
64689 ofstream 도 전역 변수로 할수 있나요? 뽀뽀중 1272 2011/06/23
64696     Re:ofstream 도 전역 변수로 할수 있나요? Nibble 1580 2011/06/24
64701         감사 합니다. 속도도 빨라지고 잘 작동 합니다. ^^ 뽀뽀중 1126 2011/06/24
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.